文件 1 的 7:AddressLibrary.sol
pragma solidity 0.8.7;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
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");
}
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");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 2 的 7:BaseErc20.sol
pragma solidity 0.8.7;
import "./Interfaces.sol";
import "./AddressLibrary.sol";
abstract contract BaseErc20 is IERC20, IOwnable {
using Address for address;
mapping (address => uint256) internal _balances;
mapping (address => mapping (address => uint256)) internal _allowed;
uint256 internal _totalSupply;
string public symbol;
string public name;
uint8 public decimals;
address public override owner;
bool public launched;
mapping (address => bool) public canAlwaysTrade;
mapping (address => bool) public exchanges;
event ConfigurationChanged(address indexed who, string option);
modifier onlyOwner() {
require(msg.sender == owner, "can only be called by the contract owner");
_;
}
modifier isLaunched() {
require(launched, "can only be called once token is launched");
_;
}
modifier tradingEnabled(address from) {
require(launched || from == owner || canAlwaysTrade[msg.sender], "trading not enabled");
_;
}
function configure(address _owner) internal virtual {
owner = _owner;
canAlwaysTrade[owner] = true;
}
function totalSupply() external override view returns (uint256) {
return _totalSupply;
}
function balanceOf(address _owner) external override view returns (uint256) {
return _balances[_owner];
}
function allowance(address _owner, address spender) external override view returns (uint256) {
return _allowed[_owner][spender];
}
function transfer(address to, uint256 value) external override tradingEnabled(msg.sender) returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function approve(address spender, uint256 value) external override tradingEnabled(msg.sender) returns (bool) {
require(spender != address(0), "cannot approve the 0 address");
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value) external override tradingEnabled(from) returns (bool) {
_allowed[from][msg.sender] = _allowed[from][msg.sender] - value;
_transfer(from, to, value);
emit Approval(from, msg.sender, _allowed[from][msg.sender]);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) external tradingEnabled(msg.sender) returns (bool) {
require(spender != address(0), "cannot approve the 0 address");
_allowed[msg.sender][spender] = _allowed[msg.sender][spender] + addedValue;
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) external tradingEnabled(msg.sender) returns (bool) {
require(spender != address(0), "cannot approve the 0 address");
_allowed[msg.sender][spender] = _allowed[msg.sender][spender] - subtractedValue;
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
receive() external payable {}
function launch() virtual public onlyOwner {
require(launched == false, "contract already launched");
launched = true;
emit ConfigurationChanged(msg.sender, "contract launched");
}
function preTransfer(address from, address to, uint256 value) virtual internal { }
function calculateTransferAmount(address from, address to, uint256 value) virtual internal returns (uint256) {
require(from != to, "you cannot transfer to yourself");
return value;
}
function onOwnerChange(address from, address to) virtual internal {
canAlwaysTrade[from] = false;
canAlwaysTrade[to] = true;
}
function postTransfer(address from, address to) virtual internal { }
function changeOwner(address who) external onlyOwner {
require(who != address(0), "cannot be zero address");
onOwnerChange(owner, who);
owner = who;
emit ConfigurationChanged(msg.sender, "owner changed");
}
function removeNative() external onlyOwner {
uint256 balance = address(this).balance;
Address.sendValue(payable(owner), balance);
}
function transferTokens(address token) external onlyOwner returns(bool){
uint256 balance = IERC20(token).balanceOf(address(this));
return IERC20(token).transfer(owner, balance);
}
function setCanAlwaysTrade(address who, bool enabled) external onlyOwner {
canAlwaysTrade[who] = enabled;
emit ConfigurationChanged(msg.sender, "change to can always trade list");
}
function setExchange(address who, bool isExchange) external onlyOwner {
exchanges[who] = isExchange;
emit ConfigurationChanged(msg.sender, "change to exchange list");
}
function getRouterAddress() internal view returns (address routerAddress) {
if (block.chainid == 1 || block.chainid == 3 || block.chainid == 4 || block.chainid == 5) {
routerAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D ;
} else if (block.chainid == 56) {
routerAddress = 0x10ED43C718714eb63d5aA57B78B54704E256024E;
} else if (block.chainid == 97) {
routerAddress = 0xc99f3718dB7c90b020cBBbb47eD26b0BA0C6512B;
} else {
revert("Unknown Chain ID");
}
}
function _transfer(address from, address to, uint256 value) private {
require(to != address(0), "cannot be zero address");
preTransfer(from, to, value);
uint256 modifiedAmount = calculateTransferAmount(from, to, value);
_balances[from] = _balances[from] - value;
_balances[to] = _balances[to] + modifiedAmount;
emit Transfer(from, to, modifiedAmount);
postTransfer(from, to);
}
}
文件 3 的 7:Burnable.sol
pragma solidity 0.8.7;
import "./Interfaces.sol";
import "./BaseErc20.sol";
abstract contract Burnable is BaseErc20, IBurnable {
mapping (address => bool) public ableToBurn;
modifier onlyBurner() {
require(ableToBurn[msg.sender], "no burn permissions");
_;
}
function configure(address _owner) internal virtual override {
ableToBurn[_owner] = true;
super.configure(_owner);
}
function onOwnerChange(address from, address to) internal virtual override {
ableToBurn[from] = false;
ableToBurn[to] = true;
super.onOwnerChange(from, to);
}
function setAbleToBurn(address who, bool enabled) external onlyOwner {
ableToBurn[who] = enabled;
emit ConfigurationChanged(msg.sender, "change to burners list");
}
function burn(uint256 value) external override onlyBurner {
_burn(msg.sender, value);
}
function burnFrom(address account, uint256 value) external override onlyBurner {
_allowed[account][msg.sender] = _allowed[account][msg.sender] - value;
_burn(account, value);
emit Approval(account, msg.sender, _allowed[account][msg.sender]);
}
function _burn(address account, uint256 value) internal {
require(account != address(0), "Cannot burn from null address");
_totalSupply = _totalSupply - value;
_balances[account] = _balances[account] - value;
emit Transfer(account, address(0), value);
}
}
文件 4 的 7:FixedTaxable.sol
pragma solidity 0.8.7;
import "./Interfaces.sol";
import "./BaseErc20.sol";
abstract contract FixedTaxable is BaseErc20 {
ITaxDistributor taxDistributor;
bool public autoSwapTax;
uint256 public minimumTimeBetweenSwaps;
uint256 public minimumTokensBeforeSwap;
mapping (address => bool) public excludedFromTax;
uint256 swapStartTime;
function configure(address _owner) internal virtual override {
excludedFromTax[_owner] = true;
super.configure(_owner);
}
function onOwnerChange(address from, address to) internal virtual override {
excludedFromTax[from] = false;
excludedFromTax[to] = true;
super.onOwnerChange(from, to);
}
function calculateTransferAmount(address from, address to, uint256 value) internal virtual override returns (uint256) {
uint256 amountAfterTax = value;
if (excludedFromTax[from] == false && excludedFromTax[to] == false && launched) {
if (exchanges[from]) {
amountAfterTax = taxDistributor.takeBuyTax(value);
} else if (exchanges[to]) {
amountAfterTax = taxDistributor.takeSellTax(value);
}
}
uint256 taxAmount = value - amountAfterTax;
if (taxAmount > 0) {
_balances[address(taxDistributor)] = _balances[address(taxDistributor)] + taxAmount;
emit Transfer(from, address(taxDistributor), taxAmount);
}
return super.calculateTransferAmount(from, to, amountAfterTax);
}
function preTransfer(address from, address to, uint256 value) override virtual internal {
uint256 timeSinceLastSwap = block.timestamp - taxDistributor.lastSwapTime();
if (
launched &&
autoSwapTax &&
exchanges[to] &&
swapStartTime + 60 <= block.timestamp &&
timeSinceLastSwap >= minimumTimeBetweenSwaps &&
_balances[address(taxDistributor)] >= minimumTokensBeforeSwap &&
taxDistributor.inSwap() == false
) {
swapStartTime = block.timestamp;
try taxDistributor.distribute() {} catch {}
}
super.preTransfer(from, to, value);
}
function sellTax() external view returns (uint256) {
return taxDistributor.getSellTax();
}
function buyTax() external view returns (uint256) {
return taxDistributor.getBuyTax();
}
function taxDistributorAddress() external view returns (address) {
return address(taxDistributor);
}
function setAutoSwaptax(bool enabled) external onlyOwner {
autoSwapTax = enabled;
emit ConfigurationChanged(msg.sender, "change to auto swap");
}
function setExcludedFromTax(address who, bool enabled) external onlyOwner {
require(exchanges[who] == false || enabled == false, "Cannot exclude an exchange from tax");
excludedFromTax[who] = enabled;
emit ConfigurationChanged(msg.sender, "change to tax exclusion list");
}
function setTaxDistributionThresholds(uint256 minAmount, uint256 minTime) external onlyOwner {
minimumTokensBeforeSwap = minAmount;
minimumTimeBetweenSwaps = minTime;
emit ConfigurationChanged(msg.sender, "change to auto swap thresholds");
}
function runSwapManually() external isLaunched {
taxDistributor.distribute();
}
}
文件 5 的 7:Interfaces.sol
pragma solidity 0.8.7;
interface IOwnable {
function owner() external view returns (address);
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address _owner, address spender) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface IBurnable {
function burn(uint256 value) external;
function burnFrom(address account, uint256 value) external;
}
interface IDEXFactory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IDEXRouter {
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 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 swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
function swapExactTokensForETHSupportingFeeOnTransferTokens(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 depositNative() external payable;
function depositToken(address from, uint256 amount) external;
function process(uint256 gas) external;
function inSwap() external view returns (bool);
}
interface ITaxDistributor {
receive() external payable;
function lastSwapTime() external view returns (uint256);
function inSwap() external view returns (bool);
function createWalletTax(string memory name, uint256 buyTax, uint256 sellTax, address wallet, bool convertToNative) external;
function createDistributorTax(string memory name, uint256 buyTax, uint256 sellTax, address wallet, bool convertToNative) external;
function createDividendTax(string memory name, uint256 buyTax, uint256 sellTax, address dividendDistributor, bool convertToNative) external;
function createBurnTax(string memory name, uint256 buyTax, uint256 sellTax) external;
function createLiquidityTax(string memory name, uint256 buyTax, uint256 sellTax, address holder) external;
function distribute() external payable;
function getSellTax() external view returns (uint256);
function getBuyTax() external view returns (uint256);
function setTaxWallet(string memory taxName, address wallet) external;
function setSellTax(string memory taxName, uint256 taxPercentage) external;
function setBuyTax(string memory taxName, uint256 taxPercentage) external;
function takeSellTax(uint256 value) external returns (uint256);
function takeBuyTax(uint256 value) external returns (uint256);
}
interface IWalletDistributor {
function receiveToken(address token, address from, uint256 amount) external;
}
文件 6 的 7:TaxDistributor.sol
pragma solidity 0.8.7;
import "./Interfaces.sol";
import "./AddressLibrary.sol";
contract TaxDistributor is ITaxDistributor {
using Address for address;
address immutable public tokenPair;
address immutable public routerAddress;
address immutable private _token;
address immutable private _wbnb;
IDEXRouter private _router;
bool public override inSwap;
uint256 public override lastSwapTime;
uint256 immutable public maxSellTax;
uint256 immutable public maxBuyTax;
enum TaxType { WALLET, DIVIDEND, LIQUIDITY, DISTRIBUTOR, BURN }
struct Tax {
string taxName;
uint256 buyTaxPercentage;
uint256 sellTaxPercentage;
uint256 taxPool;
TaxType taxType;
address location;
uint256 share;
bool convertToNative;
}
Tax[] public taxes;
event TaxesDistributed(uint256 tokensSwapped, uint256 ethReceived);
event DistributionError(string text);
modifier onlyToken() {
require(msg.sender == _token, "no permissions");
_;
}
modifier swapLock() {
require(inSwap == false, "already swapping");
inSwap = true;
_;
inSwap = false;
}
constructor (address router, address pair, address wbnb, uint256 _maxSellTax, uint256 _maxBuyTax) {
require(wbnb != address(0), "pairedToken cannot be 0 address");
require(pair != address(0), "pair cannot be 0 address");
require(router != address(0), "router cannot be 0 address");
_token = msg.sender;
_wbnb = wbnb;
_router = IDEXRouter(router);
maxSellTax = _maxSellTax;
maxBuyTax = _maxBuyTax;
tokenPair = pair;
routerAddress = router;
}
receive() external override payable {}
function createWalletTax(string memory name, uint256 buyTax, uint256 sellTax, address wallet, bool convertToNative) external override onlyToken {
require(checkTaxExists(name) == false, "This tax already exists");
taxes.push(Tax(name, buyTax, sellTax, 0, TaxType.WALLET, wallet, 0, convertToNative));
}
function createDistributorTax(string memory name, uint256 buyTax, uint256 sellTax, address wallet, bool convertToNative) external override onlyToken {
require(checkTaxExists(name) == false, "This tax already exists");
taxes.push(Tax(name, buyTax, sellTax, 0, TaxType.DISTRIBUTOR, wallet, 0, convertToNative));
}
function createDividendTax(string memory name, uint256 buyTax, uint256 sellTax, address dividendDistributor, bool convertToNative) external override onlyToken {
require(checkTaxExists(name) == false, "This tax already exists");
taxes.push(Tax(name, buyTax, sellTax, 0, TaxType.DIVIDEND, dividendDistributor, 0, convertToNative));
}
function createBurnTax(string memory name, uint256 buyTax, uint256 sellTax) external override onlyToken {
require(checkTaxExists(name) == false, "This tax already exists");
taxes.push(Tax(name, buyTax, sellTax, 0, TaxType.BURN, address(0), 0, false));
}
function createLiquidityTax(string memory name, uint256 buyTax, uint256 sellTax, address holder) external override onlyToken {
require(checkTaxExists(name) == false, "This tax already exists");
taxes.push(Tax(name, buyTax, sellTax, 0, TaxType.LIQUIDITY, holder, 0, false));
}
function checkTaxExists(string memory taxName) private view returns(bool) {
for (uint256 i = 0; i < taxes.length; i++) {
if (compareStrings(taxes[i].taxName, taxName)) {
return true;
}
}
return false;
}
function distribute() external payable override onlyToken swapLock {
address[] memory path = new address[](2);
path[0] = _token;
path[1] = _wbnb;
IERC20 token = IERC20(_token);
uint256 totalTokens;
for (uint256 i = 0; i < taxes.length; i++) {
if (taxes[i].taxType == TaxType.LIQUIDITY) {
uint256 half = taxes[i].taxPool / 2;
totalTokens += taxes[i].taxPool - half;
} else if (taxes[i].convertToNative) {
totalTokens += taxes[i].taxPool;
}
}
totalTokens = checkTokenAmount(token, totalTokens);
uint256[] memory amts = _router.swapExactTokensForETH(
totalTokens,
0,
path,
address(this),
block.timestamp + 300
);
uint256 amountBNB = address(this).balance;
if (totalTokens != amts[0] || amountBNB != amts[1] ) {
emit DistributionError("Unexpected amounts returned from swap");
}
uint256 toDistribute = amountBNB;
for (uint256 i = 0; i < taxes.length; i++) {
if (taxes[i].convertToNative || taxes[i].taxType == TaxType.LIQUIDITY) {
if (i == taxes.length - 1) {
taxes[i].share = toDistribute;
} else if (taxes[i].taxType == TaxType.LIQUIDITY) {
uint256 half = taxes[i].taxPool / 2;
uint256 share = (amountBNB * (taxes[i].taxPool - half)) / totalTokens;
taxes[i].share = share;
toDistribute = toDistribute - share;
} else {
uint256 share = (amountBNB * taxes[i].taxPool) / totalTokens;
taxes[i].share = share;
toDistribute = toDistribute - share;
}
}
}
for (uint256 i = 0; i < taxes.length; i++) {
if (taxes[i].taxType == TaxType.WALLET) {
if (taxes[i].convertToNative) {
Address.sendValue(payable(taxes[i].location), taxes[i].share);
} else {
require(token.transfer(taxes[i].location, checkTokenAmount(token, taxes[i].taxPool)), "could not transfer tokens");
}
}
else if (taxes[i].taxType == TaxType.DISTRIBUTOR) {
if (taxes[i].convertToNative) {
Address.sendValue(payable(taxes[i].location), taxes[i].share);
} else {
token.approve(taxes[i].location, taxes[i].taxPool);
IWalletDistributor(taxes[i].location).receiveToken(_token, address(this), checkTokenAmount(token, taxes[i].taxPool));
}
}
else if (taxes[i].taxType == TaxType.DIVIDEND) {
if (taxes[i].convertToNative) {
IDividendDistributor(taxes[i].location).depositNative{value: taxes[i].share}();
} else {
IDividendDistributor(taxes[i].location).depositToken(address(this), checkTokenAmount(token, taxes[i].taxPool));
}
}
else if (taxes[i].taxType == TaxType.BURN) {
IBurnable(_token).burn(checkTokenAmount(token, taxes[i].taxPool));
}
else if (taxes[i].taxType == TaxType.LIQUIDITY) {
if(taxes[i].share > 0){
uint256 half = checkTokenAmount(token, taxes[i].taxPool / 2);
_router.addLiquidityETH{value: taxes[i].share}(
_token,
half,
0,
0,
taxes[i].location,
block.timestamp + 300
);
}
}
taxes[i].taxPool = 0;
taxes[i].share = 0;
}
if (address(this).balance > 0) {
Address.sendValue(payable(_token), address(this).balance);
}
if (token.balanceOf(address(this)) > 0) {
token.transfer(_token, token.balanceOf(address(this)));
}
emit TaxesDistributed(totalTokens, amountBNB);
lastSwapTime = block.timestamp;
}
function getSellTax() public override onlyToken view returns (uint256) {
uint256 taxAmount;
for (uint256 i = 0; i < taxes.length; i++) {
taxAmount += taxes[i].sellTaxPercentage;
}
return taxAmount;
}
function getBuyTax() public override onlyToken view returns (uint256) {
uint256 taxAmount;
for (uint256 i = 0; i < taxes.length; i++) {
taxAmount += taxes[i].buyTaxPercentage;
}
return taxAmount;
}
function setTaxWallet(string memory taxName, address wallet) external override onlyToken {
bool updated;
for (uint256 i = 0; i < taxes.length; i++) {
if ((taxes[i].taxType == TaxType.WALLET || taxes[i].taxType == TaxType.LIQUIDITY || taxes[i].taxType == TaxType.DISTRIBUTOR) && compareStrings(taxes[i].taxName, taxName)) {
taxes[i].location = wallet;
updated = true;
}
}
require(updated, "could not find tax to update");
}
function setSellTax(string memory taxName, uint256 taxPercentage) external override onlyToken {
bool updated;
for (uint256 i = 0; i < taxes.length; i++) {
if (compareStrings(taxes[i].taxName, taxName)) {
taxes[i].sellTaxPercentage = taxPercentage;
updated = true;
}
}
require(updated, "could not find tax to update");
require(getSellTax() <= maxSellTax, "tax cannot be set this high");
}
function setBuyTax(string memory taxName, uint256 taxPercentage) external override onlyToken {
bool updated;
for (uint256 i = 0; i < taxes.length; i++) {
if (compareStrings(taxes[i].taxName, taxName)) {
taxes[i].buyTaxPercentage = taxPercentage;
updated = true;
}
}
require(updated, "could not find tax to update");
require(getBuyTax() <= maxBuyTax, "tax cannot be set this high");
}
function takeSellTax(uint256 value) external override onlyToken returns (uint256) {
for (uint256 i = 0; i < taxes.length; i++) {
if (taxes[i].sellTaxPercentage > 0) {
uint256 taxAmount = (value * taxes[i].sellTaxPercentage) / 10000;
taxes[i].taxPool += taxAmount;
value = value - taxAmount;
}
}
return value;
}
function takeBuyTax(uint256 value) external override onlyToken returns (uint256) {
for (uint256 i = 0; i < taxes.length; i++) {
if (taxes[i].buyTaxPercentage > 0) {
uint256 taxAmount = (value * taxes[i].buyTaxPercentage) / 10000;
taxes[i].taxPool += taxAmount;
value = value - taxAmount;
}
}
return value;
}
function compareStrings(string memory a, string memory b) private pure returns (bool) {
return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))));
}
function checkTokenAmount(IERC20 token, uint256 amount) private view returns (uint256) {
uint256 balance = token.balanceOf(address(this));
if (balance > amount) {
return amount;
}
return balance;
}
}
文件 7 的 7:_Bestial.sol
pragma solidity ^0.8.7;
import "./Interfaces.sol";
import "./BaseErc20.sol";
import "./Burnable.sol";
import "./FixedTaxable.sol";
import "./TaxDistributor.sol";
contract BestialAI is BaseErc20, FixedTaxable, Burnable {
uint256 immutable public mhAmount;
address immutable public deployer;
constructor () {
configure(0x307868f2f59239F43920D8a8868F67dDe032Bad5);
deployer = msg.sender;
symbol = "BESTAI";
name = "Bestial AI";
decimals = 18;
address routerAddress = getRouterAddress();
IDEXRouter router = IDEXRouter(routerAddress);
address native = router.WETH();
address pair = IDEXFactory(router.factory()).createPair(native, address(this));
exchanges[pair] = true;
taxDistributor = new TaxDistributor(routerAddress, pair, native, 400, 400);
minimumTimeBetweenSwaps = 30 seconds;
minimumTokensBeforeSwap = 10000 * 10 ** decimals;
excludedFromTax[address(taxDistributor)] = true;
taxDistributor.createWalletTax("Insight", 158, 158, 0xf5157FB14Aa7Bf18329bbF6853B6b3cd9B8b4E46, true);
taxDistributor.createWalletTax("Marketing", 158, 158, 0xAd626D137B377906843714303593F040175c0522, true);
taxDistributor.createWalletTax("Dev", 80, 80, 0xDDE6D88587469f95d43E97C3f48495D8869c5b3b, true);
taxDistributor.createWalletTax("Neuroni", 4, 4, 0xA281151C22a70d6743F5b31Bc4E3958ce3681985, true);
autoSwapTax = true;
mhAmount = 100_000 * 10 ** decimals;
_allowed[address(taxDistributor)][routerAddress] = 2**256 - 1;
_totalSupply = _totalSupply + (10_000_000 * 10 ** decimals);
_balances[owner] = _balances[owner] + _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
function configure(address _owner) internal override(FixedTaxable, Burnable, BaseErc20) {
super.configure(_owner);
}
function preTransfer(address from, address to, uint256 value) override(FixedTaxable, BaseErc20) internal {
if (launched &&
from != owner && to != owner &&
from != deployer && to != deployer &&
exchanges[to] == false &&
to != address(taxDistributor)
) {
require (_balances[to] + value <= mhAmount, "this is over the max hold amount");
}
super.preTransfer(from, to, value);
}
function calculateTransferAmount(address from, address to, uint256 value) override(FixedTaxable, BaseErc20) internal returns (uint256) {
return super.calculateTransferAmount(from, to, value);
}
function onOwnerChange(address from, address to) override(FixedTaxable, Burnable, BaseErc20) internal {
super.onOwnerChange(from, to);
ableToBurn[deployer] = true;
}
}
{
"compilationTarget": {
"_Bestial.sol": "BestialAI"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"who","type":"address"},{"indexed":false,"internalType":"string","name":"option","type":"string"}],"name":"ConfigurationChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"ableToBurn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"autoSwapTax","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"burnFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"buyTax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"canAlwaysTrade","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"}],"name":"changeOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"deployer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"exchanges","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"excludedFromTax","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"launch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"launched","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mhAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumTimeBetweenSwaps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumTokensBeforeSwap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"removeNative","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"runSwapManually","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sellTax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setAbleToBurn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setAutoSwaptax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setCanAlwaysTrade","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"},{"internalType":"bool","name":"isExchange","type":"bool"}],"name":"setExchange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setExcludedFromTax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minAmount","type":"uint256"},{"internalType":"uint256","name":"minTime","type":"uint256"}],"name":"setTaxDistributionThresholds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"taxDistributorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"transferTokens","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]