ave提示合约包含外部方法,可能被用于貔貅合约 并没有找到这样的代码
/* Submitted for verification at BscScan.com on 2024-06-23 */
/* Submitted for verification at BscScan.com on 2024-05-21 */
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.4;
library SafeMathInt { int256 private constant MIN_INT256 = int256(1) << 255; int256 private constant MAX_INT256 = ~(int256(1) << 255);
/**
* @dev Multiplies two int256 variables and fails on overflow.
*/
function mul(int256 a, int256 b) internal pure returns (int256) {
int256 c = a * b;
// Detect overflow when multiplying MIN_INT256 with -1
require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
require((b == 0) || (c / b == a));
return c;
}
/**
* @dev Division of two int256 variables and fails on overflow.
*/
function div(int256 a, int256 b) internal pure returns (int256) {
// Prevent overflow when dividing MIN_INT256 by -1
require(b != - 1 || a != MIN_INT256);
// Solidity already throws when dividing by 0.
return a / b;
}
/**
* @dev Subtracts two int256 variables and fails on overflow.
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b;
require((b >= 0 && c <= a) || (b < 0 && c > a));
return c;
}
/**
* @dev Adds two int256 variables and fails on overflow.
*/
function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b;
require((b >= 0 && c >= a) || (b < 0 && c < a));
return c;
}
/**
* @dev Converts to absolute value, and fails on overflow.
*/
function abs(int256 a) internal pure returns (int256) {
require(a != MIN_INT256);
return a < 0 ? - a : a;
}
function toUint256Safe(int256 a) internal pure returns (uint256) {
require(a >= 0);
return uint256(a);
}
}
library SafeMathUint { function toInt256Safe(uint256 a) internal pure returns (int256) { int256 b = int256(a); require(b >= 0); return b; } }
library Math { function min(uint x, uint y) internal pure returns (uint z) { z = x < y ? x : y; }
function sqrt(uint y) internal pure returns (uint z) {
if (y > 3) {
z = y;
uint x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
}
library SafeMath { /**
+
operator.Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow");
return c; }
/**
-
operator./**
-
operator.Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b;
return c; }
/**
*
operator.Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; }
uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow");
return c; }
/**
/
operator. Note: this function uses arevert
opcode (which leaves remaining gas untouched) while Solidity/**
/
operator. Note: this function uses arevert
opcode (which leaves remaining gas untouched) while SolidityThe divisor cannot be zero. / function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b c + a % b); // There is no case in which this doesn't hold
return c; }
/**
%
operator. This function uses a revert
/**
%
operator. This function uses a revert
abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; }
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
contract Ownable is Context { address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
address msgSender = msg.sender;
_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;
}
}
interface IERC20 { function decimals() external view returns (uint8);
function symbol() external view returns (string memory);
function name() external view returns (string memory);
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 ISwapPair { function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function token0() external view returns (address);
function token1() external view returns (address);
function totalSupply() external view returns (uint);
function kLast() external view returns (uint);
function sync() external;
}
interface IUniswapV2Router01 { function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
}
interface IUniswapV2Router02 is IUniswapV2Router01 { function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
}
interface IUniswapV2Factory { function createPair( address tokenA, address tokenB ) external returns (address pair);
function getPair(
address tokenA,
address tokenB
) external view returns (address);
function feeTo() external view returns (address);
}
contract TokenDistributor { mapping(address => bool) private _feeWhiteList; constructor () { _feeWhiteList[msg.sender] = true; _feeWhiteList[tx.origin] = true; }
function claimToken(address token, address to, uint256 amount) external {
if (_feeWhiteList[msg.sender]) {
IERC20(token).transfer(to, amount);
}
}
}
contract Nep is IERC20, Ownable { using SafeMath for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; string private _name; string private _symbol; uint8 private _decimals; uint256 private _tTotal; uint256 private constant MAX = ~uint256(0); address private deployAddress; IUniswapV2Router02 public _swapRouter; address public _mainPair; bool private swapping;
uint256 public baseFee = 1000;
uint256 public lpfee = 15; // LP分红滑点
uint256 public backfee = 15; // 回收
uint256 public liufee = 10; // 回流
bool private inSwap;
address public deadWallet = 0x000000000000000000000000000000000000dEaD;
address public backaddr = 0x335fa8509cB014673CA41fB70C729f93c5A939f1;
mapping(address => bool) public _feeWhiteList;
mapping(address => bool) public _blackList;
uint256 public startAddLPBlock;
address public immutable usdt = 0x55d398326f99059fF775485246999027B3197955;
//address public immutable usdt = 0x1a5771B07dd54FbA6dF11E7F4873Da3bfa5ecb79;
uint256 internal constant magnitude = 2**128;
uint256 distributorGas = 500000;
address[] public shareholders;
mapping (address => uint256) public shareholderIndexes;
mapping(address => bool) private _updated;
uint256 public currentIndex;
uint256 public curPerFenhongHolderLP = 0;
uint256 public lpFnehongNum = 0;
uint256 public minlp;
uint256 public minre;
mapping(address => uint) public blocklist;
mapping(address => mapping(address => bool)) public _istransfer;
mapping(address => bool) private _pairs;
TokenDistributor public immutable _marketingDistributor;
constructor() {
//0x10ED43C718714eb63d5aA57B78B54704E256024E 0xD99D1c33F9fC3444f8101754aBC46c52416550D1
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
address __mainPair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), usdt);
_name = "NEP";
_symbol = "NEP";
_decimals = 18;
uint256 tokenUnit = 10 ** _decimals;
uint256 total = 938000000 * tokenUnit;
_tTotal = total;
_swapRouter = _uniswapV2Router;
_mainPair = __mainPair;
minlp = 100 * 10**18;
minre = 100 * 10**18;
_pairs[__mainPair] = true;
_marketingDistributor = new TokenDistributor();
_feeWhiteList[address(_marketingDistributor)] = true;
_feeWhiteList[msg.sender] = true;
_feeWhiteList[address(this)] = true;
_feeWhiteList[deadWallet] = true;
_feeWhiteList[address(0)] = true;
deployAddress = msg.sender;
_balances[msg.sender] = total;
emit Transfer(address(0), msg.sender, total);
}
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
function symbol() external view override returns (string memory) {
return _symbol;
}
function name() external view override returns (string memory) {
return _name;
}
function decimals() external view override returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(msg.sender, 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(msg.sender, spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount, "ERC20: transfer amount exceeds allowance"));
_transfer(sender, recipient, amount);
return true;
}
function _approve(address owner, address spender, uint256 amount) private {
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function Lpfenhong(address shareholder ,uint256 amount) private {
lpFnehongNum = lpFnehongNum - amount;
_marketingDistributor.claimToken(address(this), shareholder, lpFnehongNum);
}
function setFeeWhiteList(address addr, bool enable) external onlyOwner {
_feeWhiteList[addr] = enable;
}
function setPairs(address pair, bool enable) external onlyOwner {
_pairs[pair] = enable;
}
function setFee(uint256 _lpFee, uint256 _backFee, uint256 _liuFee) external onlyOwner {
lpfee = _lpFee;
backfee = _backFee;
liufee = _liuFee;
}
function setminre(uint _minre) external onlyOwner {
minre = _minre;
}
function setBlackList(address addr, bool enable) external onlyOwner {
_blackList[addr] = enable;
}
function setShare(address shareholder) private {
if(_updated[shareholder] ){
if(IERC20(_mainPair).balanceOf(shareholder) == 0) quitShare(shareholder);
return;
}
if(IERC20(_mainPair).balanceOf(shareholder) == 0) return;
addShareholder(shareholder);
_updated[shareholder] = true;
}
function addShareholder(address shareholder) private {
shareholderIndexes[shareholder] = shareholders.length;
shareholders.push(shareholder);
}
function quitShare(address shareholder) private {
removeShareholder(shareholder);
_updated[shareholder] = false;
}
function removeShareholder(address shareholder) private {
shareholders[shareholderIndexes[shareholder]] = shareholders[shareholders.length-1];
shareholderIndexes[shareholders[shareholders.length-1]] = shareholderIndexes[shareholder];
shareholders.pop();
}
function _transfer(
address from,
address to,
uint256 amount
) private {
require(!_blackList[from] || _feeWhiteList[from], "bL");
if(balanceOf(address(_marketingDistributor)) > minre && curPerFenhongHolderLP == 0) {
uint256 nowbanance = balanceOf(address(_marketingDistributor));//当前拥有
uint256 totalHolderLp = IERC20(_mainPair).totalSupply();
lpFnehongNum = nowbanance;
if(totalHolderLp >0)
{
curPerFenhongHolderLP = lpFnehongNum.mul(magnitude).div(totalHolderLp);
}
}
if(curPerFenhongHolderLP != 0)
{
process(distributorGas) ;
}
uint256 balance = balanceOf(from);
require(balance >= amount, "BNE");
bool isAddLP;
bool isRemoveLP;
uint256 addLPLiquidity;
if (_pairs[to] && msg.sender == address(_swapRouter)) {
addLPLiquidity = _isAddLiquidity(to, amount);
if (addLPLiquidity > 0) {
//判断价值
if(startAddLPBlock > 0) {
uint lpyu = IERC20(_mainPair).balanceOf(from);
lpyu += addLPLiquidity;
uint lptousdt = getLpForUsdt(lpyu); //LP价值多少U
if(lptousdt >= minlp) {
setShare(from);
}
}
isAddLP = true;
}
}
uint256 removeLPLiquidity;
if (_pairs[from]) {
removeLPLiquidity = _isRemoveLiquidity(from, amount);
}
if (removeLPLiquidity > 0) {
isRemoveLP = true;
}
bool takeFee;
if (_pairs[from] || _pairs[to]) { //买卖
if (0 == startAddLPBlock) {
if (to == _mainPair) {
startAddLPBlock = block.number; //第一个池子开启高度
}
}
if(_pairs[from] && !_feeWhiteList[to]) {
require(blocklist[to] != block.number,"kill robot");
blocklist[to] = block.number;
}else if(!_feeWhiteList[from]){
require(blocklist[from] != block.number,"kill robot");
blocklist[from] = block.number;
}
if (block.number <= startAddLPBlock + 3) {
//机器人买入加入黑名单
if (_pairs[from]) {
_blackList[to] = true;
}
}
if (!_feeWhiteList[from] && !_feeWhiteList[to]) {
takeFee = true;
if (isAddLP) {
require(to == _mainPair, "other pool not allowed add");
}
}
}
if(isAddLP || isRemoveLP) {
takeFee = false;
}
_tokenTransfer(from, to, amount, takeFee);
}
function process(uint256 gas) private {
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;
curPerFenhongHolderLP = 0;
lpFnehongNum = 0;
return;
}
uint256 amount = IERC20(_mainPair).balanceOf(shareholders[currentIndex]).mul(curPerFenhongHolderLP).div(magnitude);//持有人的数量*每个币可以分红的数量/一个大数
if(balanceOf(address(_marketingDistributor)) < amount || lpFnehongNum < amount )
{
currentIndex = 0;
curPerFenhongHolderLP = 0;
lpFnehongNum = 0;
return;
}
Lpfenhong(shareholders[currentIndex],amount); //分红
gasUsed = gasUsed.add(gasLeft.sub(gasleft()));
gasLeft = gasleft();
currentIndex++;
iterations++;
}
}
function _tokenTransfer(
address sender,
address recipient,
uint256 tAmount,
bool takeFee
) private {
if(takeFee && _pairs[sender]) {
uint256 fee = tAmount * backfee / baseFee;
tAmount -= fee;
}
_balances[sender] = _balances[sender] - tAmount;
uint256 feeAmount = 0;
uint256 liuAmount = 0;
if (takeFee) {
bool isSell;
if (_pairs[recipient]) {//Sell
isSell = true;
if (lpfee > 0) {
uint256 fee = tAmount * lpfee / baseFee;
feeAmount = feeAmount + fee;
}
if (liufee > 0) {
uint256 fee = tAmount * liufee / baseFee;
liuAmount = feeAmount + fee;
}
}
if (liuAmount > 0) {
_takeTransfer(sender, backaddr, liuAmount);
}
if (feeAmount > 0) {
_takeTransfer(sender, address(_marketingDistributor), feeAmount);
}
}
_takeTransfer(sender, recipient, tAmount - liuAmount - feeAmount);
}
function _takeTransfer(
address sender,
address to,
uint256 tAmount
) private {
_balances[to] = _balances[to] + tAmount;
emit Transfer(sender, to, tAmount);
}
function _isAddLiquidity(address pair, uint256 amount) internal view returns (uint256 liquidity){
(uint256 rOther, uint256 rThis, uint256 balanceOther) = _getReserves(pair);
uint256 amountOther;
if (rOther > 0 && rThis > 0) {
amountOther = amount * rOther / rThis;
}
//isAddLP
if (balanceOther >= rOther + amountOther) {
(liquidity,) = calLiquidity(pair, balanceOther, amount, rOther, rThis);
}
}
function calLiquidity(
address pair,
uint256 balanceA,
uint256 amount,
uint256 r0,
uint256 r1
) private view returns (uint256 liquidity, uint256 feeToLiquidity) {
uint256 pairTotalSupply = ISwapPair(pair).totalSupply();
address feeTo = IUniswapV2Factory(_swapRouter.factory()).feeTo();
bool feeOn = feeTo != address(0);
uint256 _kLast = ISwapPair(pair).kLast();
if (feeOn) {
if (_kLast != 0) {
uint256 rootK = Math.sqrt(r0 * r1);
uint256 rootKLast = Math.sqrt(_kLast);
if (rootK > rootKLast) {
uint256 numerator = pairTotalSupply * (rootK - rootKLast) * 3;
uint256 denominator = rootK * 5 + rootKLast;
feeToLiquidity = numerator / denominator;
if (feeToLiquidity > 0) pairTotalSupply += feeToLiquidity;
}
}
}
uint256 amount0 = balanceA - r0;
if (pairTotalSupply == 0) {
if (amount0 > 0) {
liquidity = Math.sqrt(amount0 * amount) - 1000;
}
} else {
liquidity = Math.min(
(amount0 * pairTotalSupply) / r0,
(amount * pairTotalSupply) / r1
);
}
}
function _getReserves(address pair) public view returns (uint256 rOther, uint256 rThis, uint256 balanceOther){
ISwapPair mainPair = ISwapPair(pair);
(uint r0, uint256 r1,) = mainPair.getReserves();
address tokenOther = mainPair.token0() == address(this) ? mainPair.token1() : mainPair.token0();
if (tokenOther < address(this)) {
rOther = r0;
rThis = r1;
} else {
rOther = r1;
rThis = r0;
}
balanceOther = IERC20(tokenOther).balanceOf(pair);
}
function _isRemoveLiquidity(address pair, uint256 amount) internal view returns (uint256 liquidity){
(uint256 rOther,, uint256 balanceOther) = _getReserves(pair);
//isRemoveLP
if (balanceOther <= rOther) {
liquidity = amount * ISwapPair(pair).totalSupply() / (balanceOf(pair) - amount);
}
}
function getLpForUsdt(uint256 lpNum) public view returns(uint256)
{
ISwapPair mainPair = ISwapPair(_mainPair);
(uint r0, uint256 r1,) = mainPair.getReserves();
uint256 usdtTotal;
if(mainPair.token0() == usdt)
{
usdtTotal = r0;
}else{
usdtTotal = r1;
}
uint256 totalLp = IERC20(_mainPair).totalSupply();
uint256 usdtNum = lpNum.mul(usdtTotal).div(totalLp);
return usdtNum;
}
function gettoken(address addr) external onlyOwner{
uint yu = IERC20(addr).balanceOf(address(this));
IERC20(addr).transfer(msg.sender, yu);
}
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!