文件 1 的 1:LILMIG.sol
pragma solidity 0.8.22;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address _account) external view returns (uint256);
function decimals() external view returns (uint8);
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
);
}
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
_setOwner(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
interface IDexSwapFactory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IDexSwapRouter {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
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;
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
}
interface IDividendDistributor {
function setDistributionCriteria(uint256 _minPeriod, uint256 _minDistribution) external;
function setShare(address shareholder, uint256 amount) external;
function deposit() external payable;
function process(uint256 gas) external;
}
contract DividendDistributor is IDividendDistributor {
using SafeMath for uint256;
address _token;
address public _ownable;
struct Share {
uint256 amount;
uint256 totalExcluded;
uint256 totalRealised;
}
IERC20 rewardToken;
IDexSwapRouter router;
address[] shareholders;
mapping (address => uint256) shareholderIndexes;
mapping (address => uint256) shareholderClaims;
mapping (address => Share) public shares;
uint256 public totalShares;
uint256 public totalDividends;
uint256 public totalDistributed;
uint256 public dividendsPerShare;
uint256 public currentIndex;
uint256 public dividendsPerShareAccuracyFactor;
uint256 public minPeriod = 2 minutes;
uint256 public minDistribution;
modifier onlyToken() {
require(msg.sender == _token); _;
}
modifier onlyOwnable() {
require(msg.sender == _ownable); _;
}
constructor (address _router, address _rewardToken, uint factor, uint rewardDecimals, address divOwn) {
router = IDexSwapRouter(_router);
rewardToken = IERC20(_rewardToken);
minDistribution = 1 * (10 ** rewardDecimals);
dividendsPerShareAccuracyFactor = 10 ** factor;
_token = msg.sender;
_ownable = divOwn;
}
function setDistributionCriteria(uint256 _minPeriod, uint256 _minDistribution) external onlyOwnable {
minPeriod = _minPeriod;
minDistribution = _minDistribution;
}
function setShare(address shareholder, uint256 amount) external override onlyToken {
if(shares[shareholder].amount > 0){
distributeDividend(shareholder);
}
if(amount > 0 && shares[shareholder].amount == 0){
addShareholder(shareholder);
}else if(amount == 0 && shares[shareholder].amount > 0){
removeShareholder(shareholder);
}
totalShares = totalShares.sub(shares[shareholder].amount).add(amount);
shares[shareholder].amount = amount;
shares[shareholder].totalExcluded = getCumulativeDividends(shares[shareholder].amount);
}
function rescueToken(address tokenAddress,address _receiver, uint256 tokens) external onlyOwnable {
IERC20(tokenAddress).transfer(_receiver, tokens);
}
function rescueFunds(address recipient, uint _amount) external onlyOwnable {
payable(recipient).transfer(_amount);
}
function deposit() external payable override onlyToken {
uint256 balanceBefore = rewardToken.balanceOf(address(this));
address[] memory path = new address[](2);
path[0] = router.WETH();
path[1] = address(rewardToken);
router.swapExactETHForTokens{value: msg.value}(
1,
path,
address(this),
block.timestamp
);
uint256 amount = rewardToken.balanceOf(address(this)).sub(balanceBefore);
totalDividends = totalDividends.add(amount);
dividendsPerShare = dividendsPerShare.add(dividendsPerShareAccuracyFactor.mul(amount).div(totalShares));
}
function process(uint256 gas) external override onlyToken {
uint256 shareholderCount = shareholders.length;
if(shareholderCount == 0) { return; }
uint256 gasUsed = 0;
uint256 gasLeft = gasleft();
uint256 iterations = 0;
while(gasUsed < gas && iterations < shareholderCount) {
if(currentIndex >= shareholderCount){
currentIndex = 0;
}
if(shouldDistribute(shareholders[currentIndex])){
distributeDividend(shareholders[currentIndex]);
}
gasUsed = gasUsed.add(gasLeft.sub(gasleft()));
gasLeft = gasleft();
currentIndex++;
iterations++;
}
}
function shouldDistribute(address shareholder) internal view returns (bool) {
return shareholderClaims[shareholder] + minPeriod < block.timestamp && getUnpaidEarnings(shareholder) > minDistribution;
}
function distributeDividend(address shareholder) internal {
if(shares[shareholder].amount == 0){ return; }
uint256 amount = getUnpaidEarnings(shareholder);
if(amount > 0){
totalDistributed = totalDistributed.add(amount);
shareholderClaims[shareholder] = block.timestamp;
shares[shareholder].totalRealised = shares[shareholder].totalRealised.add(amount);
shares[shareholder].totalExcluded = getCumulativeDividends(shares[shareholder].amount);
rewardToken.transfer(shareholder, amount);
}
}
function claimDividend() external {
distributeDividend(msg.sender);
}
function getUnpaidEarnings(address shareholder) public view returns (uint256) {
if(shares[shareholder].amount == 0){ return 0; }
uint256 shareholderTotalDividends = getCumulativeDividends(shares[shareholder].amount);
uint256 shareholderTotalExcluded = shares[shareholder].totalExcluded;
if(shareholderTotalDividends <= shareholderTotalExcluded){ return 0; }
return shareholderTotalDividends.sub(shareholderTotalExcluded);
}
function getCumulativeDividends(uint256 share) internal view returns (uint256) {
return share.mul(dividendsPerShare).div(dividendsPerShareAccuracyFactor);
}
function addShareholder(address shareholder) internal {
shareholderIndexes[shareholder] = shareholders.length;
shareholders.push(shareholder);
}
function removeShareholder(address shareholder) internal {
shareholders[shareholderIndexes[shareholder]] = shareholders[shareholders.length-1];
shareholderIndexes[shareholders[shareholders.length-1]] = shareholderIndexes[shareholder];
shareholders.pop();
}
}
contract LILMIG is Context, IERC20, Ownable {
using SafeMath for uint256;
string private _name = "Lil Miggles";
string private _symbol = "LILMIG";
uint8 private _decimals = 9;
address public marketingWallet = address(0x3B01de5f52C20c78A94ce5325aCcCb444d14bBaA);
struct feeStruct {
uint256 buyRewardFee;
uint256 buyMarketingFee;
uint256 sellMarketingFee;
uint256 sellRewardFee;
uint256 denominator;
}
feeStruct public fee;
mapping (address => uint256) _balances;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) public IsChargePair;
mapping (address => bool) public isMarketPair;
mapping(address => bool) public isDividendExempt;
uint256 private _totalSupply = 10_000_000 * 10**_decimals;
uint256 public maxTransaction = _totalSupply.mul(2).div(100);
uint256 public maxWallet = _totalSupply.mul(2).div(100);
uint256 public swapThreshold = _totalSupply.mul(5).div(100000);
bool public swapEnabled = true;
bool public swapbylimit = false;
bool public secureWhale = true;
DividendDistributor distributor;
address public dividendReciever;
uint256 distributorGas = 500000;
IDexSwapRouter public dexRouter;
address public dexPair;
bool inSwap;
modifier swapping() {
inSwap = true;
_;
inSwap = false;
}
event SwapTokensForETH(
uint256 amountIn,
address[] path
);
constructor(address _rToken, uint _rtokenDecimal) {
address _router = address(0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24);
uint factor = uint(_decimals) + uint(_rtokenDecimal);
IDexSwapRouter _dexRouter = IDexSwapRouter(
_router
);
dexPair = IDexSwapFactory(_dexRouter.factory()).createPair(address(this),_dexRouter.WETH());
distributor = new DividendDistributor(_router, _rToken, factor, _rtokenDecimal, msg.sender);
dividendReciever = address(distributor);
isDividendExempt[msg.sender] = true;
isDividendExempt[dexPair] = true;
isDividendExempt[address(this)] = true;
isDividendExempt[address(0xdead)] = true;
isDividendExempt[address(0x0)] = true;
dexRouter = _dexRouter;
isMarketPair[dexPair] = true;
IsChargePair[address(this)] = true;
IsChargePair[msg.sender] = true;
IsChargePair[marketingWallet] = true;
fee = feeStruct(3,2,2,5,100);
_balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
function name() public 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 _totalSupply;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
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 _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);
}
receive() external payable {}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, 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 _transfer(address sender, address recipient, uint256 amount) private returns (bool) {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if (inSwap) {
return _basicTransfer(sender, recipient, amount);
}
else {
if(!IsChargePair[sender] && !IsChargePair[recipient] && secureWhale) {
require(amount <= maxTransaction, "Exceeds maxTxAmount");
if(!isMarketPair[recipient]) {
require(balanceOf(recipient).add(amount) <= maxWallet, "Exceeds maxWallet");
}
}
uint256 contractTokenBalance = balanceOf(address(this));
bool overMinimumTokenBalance = contractTokenBalance >= swapThreshold;
if (overMinimumTokenBalance &&
!inSwap &&
!isMarketPair[sender] &&
swapEnabled &&
!IsChargePair[sender] &&
!IsChargePair[recipient]
) {
swapBack(contractTokenBalance);
}
_balances[sender] = _balances[sender].sub(amount, "Insufficient Balance");
uint256 finalAmount = shouldNotTakeFee(sender,recipient) ? amount : takeFee(sender, recipient, amount);
_balances[recipient] = _balances[recipient].add(finalAmount);
if(!isDividendExempt[sender]){ try distributor.setShare(sender, balanceOf(sender)) {} catch {} }
if(!isDividendExempt[recipient]){ try distributor.setShare(recipient, balanceOf(recipient)) {} catch {} }
try distributor.process(distributorGas) {} catch {}
emit Transfer(sender, recipient, finalAmount);
return true;
}
}
function manualProcess() external {
try distributor.process(distributorGas) {} catch {}
}
function _basicTransfer(address sender, address recipient, uint256 amount) internal returns (bool) {
_balances[sender] = _balances[sender].sub(amount, "Insufficient Balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
return true;
}
function shouldNotTakeFee(address sender, address recipient) internal view returns (bool) {
if(IsChargePair[sender] || IsChargePair[recipient]) {
return true;
}
else if (isMarketPair[sender] || isMarketPair[recipient]) {
return false;
}
else {
return true;
}
}
function takeFee(address sender, address recipient, uint256 amount) internal returns (uint256) {
uint feeAmount;
uint rewardFee;
uint marketingFee;
unchecked {
if(isMarketPair[sender]) {
marketingFee = amount.mul(fee.buyMarketingFee).div(fee.denominator);
rewardFee = amount.mul(fee.buyRewardFee).div(fee.denominator);
feeAmount = marketingFee.add(rewardFee);
}
else if(isMarketPair[recipient]) {
marketingFee = amount.mul(fee.sellMarketingFee).div(fee.denominator);
rewardFee = amount.mul(fee.sellRewardFee).div(fee.denominator);
feeAmount = marketingFee.add(rewardFee);
}
if(feeAmount > 0) {
_balances[address(this)] = _balances[address(this)].add(feeAmount);
emit Transfer(sender, address(this), feeAmount);
}
return amount.sub(feeAmount);
}
}
function swapBack(uint contractBalance) internal swapping {
if (swapbylimit) contractBalance = swapThreshold;
uint rewardShare = fee.buyRewardFee.add(fee.buyRewardFee);
uint marketingShare = fee.buyMarketingFee.add(fee.sellMarketingFee);
uint totalShares = rewardShare.add(marketingShare);
uint256 initialBalance = address(this).balance;
swapTokensForEth(contractBalance);
uint256 amountReceived = address(this).balance.sub(initialBalance);
uint marketingEth = amountReceived.mul(marketingShare).div(totalShares);
uint rewardEth = amountReceived.sub(marketingEth);
if(rewardEth > 0) {
try distributor.deposit { value: rewardEth } () {} catch {}
}
if(marketingEth > 0) {
(bool os,) = payable(marketingWallet).call{value: marketingEth}("");
os = true;
}
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = dexRouter.WETH();
_approve(address(this), address(dexRouter), tokenAmount);
dexRouter.swapExactTokensForETH(
tokenAmount,
1,
path,
address(this),
block.timestamp + 30
);
emit SwapTokensForETH(tokenAmount, path);
}
function setMarketingWallet(address newAddress) external onlyOwner {
marketingWallet = newAddress;
}
function rescueFunds() external onlyOwner {
(bool os,) = payable(msg.sender).call{value: address(this).balance}("");
require(os,"Transaction Failed!!");
}
function rescueTokens(address _token,address recipient,uint _amount) external onlyOwner {
(bool success, ) = address(_token).call(abi.encodeWithSignature('transfer(address,uint256)', recipient, _amount));
require(success, 'Token payment failed');
}
function setFeeSetting(uint _buyMarketing, uint _buyReward, uint _sellMarketing, uint _sellReward) external onlyOwner {
uint buy_Subtotal;
uint sell_Subtotal;
fee.buyRewardFee = _buyReward;
fee.buyMarketingFee = _buyMarketing;
fee.sellMarketingFee = _sellMarketing;
fee.sellRewardFee = _sellReward;
buy_Subtotal = _buyReward.add(_buyMarketing);
sell_Subtotal = _sellMarketing.add(_sellReward);
require(buy_Subtotal >= 1 && sell_Subtotal >= 1,"Error: Cant set less tax than 1%");
require(buy_Subtotal <= 30 && sell_Subtotal <= 30,"Error: Cant set more tax than 30%");
}
function setChargeFee(address _adr,bool _status) external onlyOwner {
IsChargePair[_adr] = _status;
}
function setDistributorSettings(uint256 gas) external onlyOwner {
require(gas < 750000, "Gas must be lower than 750000");
distributorGas = gas;
}
function setAntiWhalePercentage(uint256 _per) external onlyOwner() {
require(_per >= 5 && secureWhale,"Minimum Limit is 0.5% or Whale Must be Active");
maxTransaction = _totalSupply.mul(_per).div(1000);
maxWallet = _totalSupply.mul(_per).div(1000);
}
function removeLimits() external onlyOwner {
maxTransaction = _totalSupply;
maxWallet = _totalSupply;
secureWhale = false;
}
function setDividendOrder(address holder, bool exempt) external onlyOwner {
require(holder != address(this) && !IsChargePair[holder]);
isDividendExempt[holder] = exempt;
if (exempt) {
distributor.setShare(holder, 0);
} else {
distributor.setShare(holder, balanceOf(holder));
}
}
function setSwapBackSettings(bool _enabled, bool _limited, uint _threshold)
external
onlyOwner
{
swapEnabled = _enabled;
swapbylimit = _limited;
swapThreshold = _threshold;
}
}