文件 1 的 1:BABYTOSHI.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 IUniswapV3SwapCallback {
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external;
}
interface ISwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}
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;
uint24 public tokenFee;
ISwapRouter public uniswapV3Router;
address public WETH;
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 = 5 minutes;
uint256 public minDistribution;
modifier onlyToken() {
require(msg.sender == _token); _;
}
modifier onlyOwnable() {
require(msg.sender == _ownable); _;
}
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);
constructor (address _router, address _weth, uint24 _tokenFee, address _rewardToken, uint factor, uint minDist, address divOwn) {
uniswapV3Router = ISwapRouter(_router);
WETH = address(_weth);
tokenFee = _tokenFee;
rewardToken = IERC20(_rewardToken);
minDistribution = minDist;
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 {
uint _value = msg.value;
uint256 balanceBefore = rewardToken.balanceOf(address(this));
address[] memory path = new address[](2);
path[0] = address(WETH);
path[1] = address(rewardToken);
uniswapV3Router.exactInputSingle{value: _value}(
ISwapRouter.ExactInputSingleParams({
tokenIn: path[0],
tokenOut: path[1],
fee: tokenFee,
recipient: address(this),
amountIn: _value,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
})
);
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();
}
function transferOwnership(address _newOwner) external onlyOwnable() {
address previous = _ownable;
_ownable = _newOwner;
emit OwnershipTransferred(previous,_newOwner);
}
receive() external payable {}
}
contract BABYTOSHI is Context, IERC20, Ownable {
using SafeMath for uint256;
string private _name = "Baby Toshi";
string private _symbol = "BTOSHI";
uint8 private _decimals = 9;
address public marketingWallet = address(0xaa8C31bdE3F497a03e890012AB2869Fff82b5E27);
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 = 1_000_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(10000);
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, uint24 _fee, uint256 minDist) {
address _v2Router = address(0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24);
address _v3Router = address(0x2626664c2603336E57B271c5C0b26F421741e481);
IDexSwapRouter _dexRouter = IDexSwapRouter(
_v2Router
);
uint _rtokenDecimal = IERC20(_rToken).decimals();
uint factor = uint(_decimals) + uint(_rtokenDecimal);
address _WETH = address(_dexRouter.WETH());
dexPair = IDexSwapFactory(_dexRouter.factory()).createPair(address(this),_dexRouter.WETH());
distributor = new DividendDistributor(_v3Router, _WETH , _fee, _rToken, factor, minDist, 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,3,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.swapExactTokensForETHSupportingFeeOnTransferTokens(
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;
}
}