Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
pragma solidity ^0.8.27;
// SPDX-License-Identifier: Unlicensed
interface IBEP20 {
function totalSupply() external view returns (uint256);
function decimals() external view returns (uint8);
function symbol() external view returns (string memory);
function name() external view returns (string memory);
function getOwner() external view returns (address);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address _owner, address spender) external view returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface IBEP20Extended is IBEP20 {
function pancakeRouter() external view returns (address);
function pancakePair() external view returns (address);
}
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; }
function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; }
function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; }
function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; }
function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; }
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) { return payable(msg.sender); }
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
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);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(account) }
return size > 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 functionCall(target, data, "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");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(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) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(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) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() { _status = _NOT_ENTERED; }
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
contract Ownable is Context {
address private _owner;
constructor() {
_owner = _msgSender();
emit OwnershipTransferred(address(0), _owner);
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function owner() public view returns (address) { return _owner; }
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
}
contract BSCPreSale is ReentrancyGuard, Context, Ownable {
using Address for address;
using SafeMath for uint256;
IERC20 public token;
IERC20 public USDT;
mapping(address => uint256) public _airdropPoints;
mapping(address => uint256) public _refCount;
mapping(address => uint256) public _sumETH;
mapping(address => uint256) public _sumUSDT;
mapping(address => bool) public isAffiliate;
mapping(address => uint256) public _affiliateETHCommission;
mapping(address => uint256) public _affiliateUSDTCommission;
bool public saleStarted = false;
uint256 private _referPercent;
uint256 private _priceETH;
uint256 private _priceUSDT;
uint256 private _saleCount;
uint256 public _ETHSold;
uint256 public _USDTSold;
address payable public saleReceiver;
address payable public feeReceiver;
uint256 public feePercent = 1;
uint256 public affiliateCommissionPercent = 50;
uint256 public kycFeePercent = 1;
uint256 public kycFeeCap = 0.12 ether;
uint256 public totalKycFeesCollected;
uint8 public USDTDecimals;
bool public affiliateSystemEnabled = false;
bool public kycFeeEnabled = false;
event AffiliateSystemToggled(bool enabled);
event KycFeeCharged(address indexed buyer, uint256 kycFeeAmount, uint256 totalKycFeesCollected);
event AffiliateCommissionPaid(address indexed affiliate, uint256 amount);
event AffiliateStatusChanged(address indexed user, bool isActive);
event KycFeeSystemToggled(bool enabled);
mapping(address => uint256) public affiliateSumETH;
mapping(address => uint256) public affiliateSumUSDT;
uint256 public USDTBonusThreshold = 2000 * 10**18;
uint256 public ethBonusThreshold = 2 ether;
uint256 public USDTBonusTokens = 25000 * 10**18;
uint256 public ethBonusTokens = 25000 * 10**18;
mapping(address => bool) public claimedUSDTBonus;
mapping(address => bool) public claimedETHBonus;
constructor(IERC20 _token, IERC20 _USDT) {
require(address(_token) != address(0), "Invalid token address");
require(address(_USDT) != address(0), "Invalid USDT address");
token = _token;
USDT = _USDT;
USDTDecimals = 18;
}
receive() external payable nonReentrant {
require(saleStarted, "Pre-sale not started");
require(msg.value >= 0.00036 ether && msg.value <= 100 ether, "Value out of range: 0.00036 to 100 ETH");
require(saleReceiver != address(0), "Sale receiver not set");
require(feeReceiver != address(0), "Fee receiver not set");
uint256 tokens = _priceETH.mul(msg.value).div(1 ether).mul(10**18);
require(token.balanceOf(address(this)) >= tokens, "Insufficient tokens for sale");
uint256 feeAmount = msg.value.mul(feePercent).div(100);
uint256 kycFeeAmount = 0;
if (kycFeeEnabled && totalKycFeesCollected < kycFeeCap) {
kycFeeAmount = msg.value.mul(kycFeePercent).div(100);
uint256 potentialKycTotal = totalKycFeesCollected.add(kycFeeAmount);
if (potentialKycTotal > kycFeeCap) {
kycFeeAmount = kycFeeCap.sub(totalKycFeesCollected);
}
totalKycFeesCollected = totalKycFeesCollected.add(kycFeeAmount);
emit KycFeeCharged(msg.sender, kycFeeAmount, totalKycFeesCollected);
}
uint256 saleAmount = msg.value.sub(feeAmount).sub(kycFeeAmount);
token.transfer(msg.sender, tokens);
(bool successSale, ) = saleReceiver.call{value: saleAmount}("");
require(successSale, "Sale transfer failed");
if (feeAmount > 0 || kycFeeAmount > 0) {
(bool successFee, ) = feeReceiver.call{value: feeAmount.add(kycFeeAmount)}("");
require(successFee, "Fee transfer failed");
}
_ETHSold = _ETHSold.add(msg.value);
_saleCount++;
}
function setUSDTDecimals(uint8 _decimals) external onlyOwner {
require(_decimals <= 18, "Invalid decimals");
USDTDecimals = _decimals;
}
function toggleAffiliateSystem() external onlyOwner {
affiliateSystemEnabled = !affiliateSystemEnabled;
emit AffiliateSystemToggled(affiliateSystemEnabled);
}
function toggleKycFeeSystem() external onlyOwner {
kycFeeEnabled = !kycFeeEnabled;
emit KycFeeSystemToggled(kycFeeEnabled);
}
function becomeAffiliate() external {
require(affiliateSystemEnabled, "Affiliate system is disabled");
require(!isAffiliate[msg.sender], "Already an affiliate");
require(token.balanceOf(msg.sender) >= 1 * 10**18, "Must hold at least 1 token");
isAffiliate[msg.sender] = true;
emit AffiliateStatusChanged(msg.sender, true);
}
function toggleAffiliateStatus(address user) external onlyOwner {
require(user != address(0), "Invalid address");
isAffiliate[user] = !isAffiliate[user];
emit AffiliateStatusChanged(user, isAffiliate[user]);
}
function setAffiliateCommissionPercent(uint256 _newPercent) external onlyOwner {
require(_newPercent <= 100, "Percentage must be between 0 and 100");
affiliateCommissionPercent = _newPercent;
}
function setToken(address _newToken) external onlyOwner {
require(_newToken != address(0), "Invalid address");
token = IERC20(_newToken);
}
function setUSDT(address _newUSDT) external onlyOwner {
require(_newUSDT != address(0), "Invalid address");
USDT = IERC20(_newUSDT);
}
function setUSDTBonusThreshold(uint256 _newThreshold) external onlyOwner {
require(_newThreshold > 0, "Threshold deve ser maior que zero");
USDTBonusThreshold = _newThreshold;
}
function setEthBonusThreshold(uint256 _newThreshold) external onlyOwner {
require(_newThreshold > 0, "Threshold deve ser maior que zero");
ethBonusThreshold = _newThreshold;
}
function setUSDTBonusTokens(uint256 _newBonus) external onlyOwner {
require(_newBonus > 0, "min 1");
USDTBonusTokens = _newBonus;
}
function setEthBonusTokens(uint256 _newBonus) external onlyOwner {
require(_newBonus > 0, "min 1");
ethBonusTokens = _newBonus;
}
function claimBonus() external nonReentrant {
require(isAffiliate[msg.sender], "Only affiliators");
uint256 tokensToClaim;
if (affiliateSumUSDT[msg.sender] >= USDTBonusThreshold && !claimedUSDTBonus[msg.sender]) {
tokensToClaim = tokensToClaim.add(USDTBonusTokens);
claimedUSDTBonus[msg.sender] = true;
}
if (affiliateSumETH[msg.sender] >= ethBonusThreshold && !claimedETHBonus[msg.sender]) {
tokensToClaim = tokensToClaim.add(ethBonusTokens);
claimedETHBonus[msg.sender] = true;
}
require(tokensToClaim > 0, "Nenhum bonus disponivel");
require(token.balanceOf(address(this)) >= tokensToClaim, "Tokens insuficientes para bonus");
token.transfer(msg.sender, tokensToClaim);
}
function setKycFeePercent(uint256 _newPercent) external onlyOwner {
require(_newPercent <= 100, "Percentage must be between 0 and 100");
kycFeePercent = _newPercent;
}
function setKycFeeCap(uint256 _newCap) external onlyOwner {
require(_newCap > 0, "Fee cap must be greater than 0");
kycFeeCap = _newCap;
}
function buyWithBNB(address _refer) external payable nonReentrant returns (bool success) {
require(saleStarted, "Pre-sale not started");
require(msg.value >= 0.00036 ether && msg.value <= 100 ether, "Value out of range: 0.00036 to 100 ETH");
require(saleReceiver != address(0), "Sale receiver not set");
require(feeReceiver != address(0), "Fee receiver not set");
uint256 tokens = _priceETH.mul(msg.value).div(1 ether).mul(10**18);
uint256 feeAmount = msg.value.mul(feePercent).div(100);
uint256 kycFeeAmount = 0;
if (kycFeeEnabled && totalKycFeesCollected < kycFeeCap) {
kycFeeAmount = msg.value.mul(kycFeePercent).div(100);
uint256 potentialKycTotal = totalKycFeesCollected.add(kycFeeAmount);
if (potentialKycTotal > kycFeeCap) {
kycFeeAmount = kycFeeCap.sub(totalKycFeesCollected);
}
totalKycFeesCollected = totalKycFeesCollected.add(kycFeeAmount);
emit KycFeeCharged(msg.sender, kycFeeAmount, totalKycFeesCollected);
}
uint256 affiliateCommission = 0;
if (_refer != address(0) && _refer != msg.sender && token.balanceOf(_refer) > 0) {
if (isAffiliate[_refer]) {
affiliateCommission = msg.value.mul(affiliateCommissionPercent).div(100);
(bool successAffiliate, ) = _refer.call{value: affiliateCommission}("");
require(successAffiliate, "Affiliate commission transfer failed");
_affiliateETHCommission[_refer] = _affiliateETHCommission[_refer].add(affiliateCommission);
emit AffiliateCommissionPaid(_refer, affiliateCommission);
}
}
uint256 saleAmount = msg.value.sub(feeAmount).sub(kycFeeAmount).sub(affiliateCommission);
_processPurchase(_msgSender(), _refer, tokens, msg.value, true);
(bool successSale, ) = saleReceiver.call{value: saleAmount}("");
require(successSale, "Sale transfer failed");
if (feeAmount > 0 || kycFeeAmount > 0) {
(bool successFee, ) = feeReceiver.call{value: feeAmount.add(kycFeeAmount)}("");
require(successFee, "Fee transfer failed");
}
_ETHSold = _ETHSold.add(msg.value);
_saleCount++;
return true;
}
function buyWithUSDT(uint256 USDTAmount, address _refer) external nonReentrant returns (bool success) {
require(saleStarted, "Pre-sale not started");
require(USDTAmount >= 1 * 10**USDTDecimals && USDTAmount <= 100000 * 10**USDTDecimals, "Value out of range: 10 to 100000 USDT");
require(saleReceiver != address(0), "Sale receiver not set");
require(feeReceiver != address(0), "Fee receiver not set");
uint256 tokens = _priceUSDT.mul(USDTAmount).div(10**USDTDecimals).mul(10**18);
uint256 feeAmount = USDTAmount.mul(feePercent).div(100);
uint256 affiliateCommission = 0;
if (_refer != address(0) && _refer != msg.sender && token.balanceOf(_refer) > 0) {
if (isAffiliate[_refer]) {
affiliateCommission = USDTAmount.mul(affiliateCommissionPercent).div(100);
require(USDT.transferFrom(msg.sender, _refer, affiliateCommission), "Affiliate commission USDT transfer failed");
_affiliateUSDTCommission[_refer] = _affiliateUSDTCommission[_refer].add(affiliateCommission);
emit AffiliateCommissionPaid(_refer, affiliateCommission);
}
}
uint256 saleAmount = USDTAmount.sub(feeAmount).sub(affiliateCommission);
require(USDT.transferFrom(msg.sender, saleReceiver, saleAmount), "USDT sale transfer failed");
require(USDT.transferFrom(msg.sender, feeReceiver, feeAmount), "USDT fee transfer failed");
_processPurchase(_msgSender(), _refer, tokens, USDTAmount, false);
_USDTSold = _USDTSold.add(USDTAmount);
_saleCount++;
return true;
}
function startSale(uint256 referPercent, uint256 salePriceETH, uint256 salePriceUSDT, uint256 tokenAmount, address payable _feeReceiver) external onlyOwner {
require(!saleStarted, "Pre-sale already started");
require(referPercent >= 0 && referPercent <= 100, "Refer percent must be between 0 and 100");
require(salePriceETH > 0, "ETH sale price must be greater than zero");
require(salePriceUSDT > 0, "USDT sale price must be greater than zero");
require(tokenAmount > 0, "Token amount must be greater than zero");
require(_feeReceiver != address(0), "Invalid fee receiver address");
_referPercent = referPercent;
_priceETH = salePriceETH;
_priceUSDT = salePriceUSDT;
feeReceiver = _feeReceiver;
require(token.transferFrom(msg.sender, address(this), tokenAmount), "Token transfer failed");
saleStarted = true;
}
function setSaleReceiver(address payable _receiver) external onlyOwner {
require(_receiver != address(0), "Invalid address");
saleReceiver = _receiver;
}
function setFeeReceiver(address payable _receiver) external onlyOwner {
require(_receiver != address(0), "Invalid fee receiver address");
feeReceiver = _receiver;
}
function setFeePercent(uint256 _newFeePercent) external onlyOwner {
require(_newFeePercent >= 0 && _newFeePercent <= 100, "Fee percent must be between 0 and 100");
feePercent = _newFeePercent;
}
function migrateETHSold(uint256 newAmountWei) external onlyOwner {
_ETHSold = newAmountWei;
}
function closeSale() external onlyOwner {
require(saleStarted, "Pre-sale not started");
saleStarted = false;
uint256 remainingTokens = token.balanceOf(address(this));
if (remainingTokens > 0) {
token.transfer(owner(), remainingTokens);
}
uint256 remainingETH = address(this).balance;
if (remainingETH > 0) {
(bool success, ) = payable(owner()).call{value: remainingETH}("");
require(success, "ETH transfer failed");
}
uint256 remainingUSDT = USDT.balanceOf(address(this));
if (remainingUSDT > 0) {
USDT.transfer(owner(), remainingUSDT);
}
}
function _processPurchase(address buyer, address refer, uint256 tokens, uint256 amount, bool isETH) private {
if (buyer != refer && token.balanceOf(refer) > 0 && refer != address(0) && !isAffiliate[refer]) {
uint256 referTokens = tokens.mul(_referPercent).div(100);
require(token.balanceOf(address(this)) >= tokens.add(referTokens), "Insufficient tokens for sale + referral");
_airdropPoints[refer] = _airdropPoints[refer].add(2);
_refCount[refer] = _refCount[refer].add(1);
_airdropPoints[buyer] = _airdropPoints[buyer].add(3);
if (isETH) {
_sumETH[buyer] = _sumETH[buyer].add(amount);
} else {
_sumUSDT[buyer] = _sumUSDT[buyer].add(amount);
}
token.transfer(refer, referTokens);
token.transfer(buyer, tokens);
} else {
require(token.balanceOf(address(this)) >= tokens, "Insufficient tokens for sale");
_airdropPoints[buyer] = _airdropPoints[buyer].add(3);
if (isETH) {
_sumETH[buyer] = _sumETH[buyer].add(amount);
} else {
_sumUSDT[buyer] = _sumUSDT[buyer].add(amount);
}
if (refer != address(0) && buyer != refer && token.balanceOf(refer) > 0 && isAffiliate[refer]) {
_airdropPoints[refer] = _airdropPoints[refer].add(2);
_refCount[refer] = _refCount[refer].add(1);
if (isETH) {
affiliateSumETH[refer] = affiliateSumETH[refer].add(amount);
} else {
affiliateSumUSDT[refer] = affiliateSumUSDT[refer].add(amount);
}
}
token.transfer(buyer, tokens);
}
}
function getTokens(uint256 amountPercent) external onlyOwner {
require(amountPercent >= 0 && amountPercent <= 100, "Percent must be between 0 and 100");
uint256 tokenAmount = token.balanceOf(address(this));
if (tokenAmount > 0) {
uint256 amountToWithdraw = tokenAmount.mul(amountPercent).div(100);
token.transfer(owner(), amountToWithdraw);
}
}
function changeSaleInfo(uint256 newReferPercent, uint256 newPriceETH, uint256 newPriceUSDT, uint256 newTokenAmount) external onlyOwner {
require(newReferPercent >= 0 && newReferPercent <= 100, "Refer percent must be between 0 and 100");
require(newPriceETH > 0, "ETH sale price must be greater than zero");
require(newPriceUSDT > 0, "USDT sale price must be greater than zero");
_referPercent = newReferPercent;
_priceETH = newPriceETH;
_priceUSDT = newPriceUSDT;
if (newTokenAmount > 0) {
require(token.transferFrom(msg.sender, address(this), newTokenAmount), "Token transfer failed");
}
}
function withdrawAllETH(uint256 amountPercent) external onlyOwner {
require(amountPercent >= 0 && amountPercent <= 100, "Percent must be between 0 and 100");
uint256 ETHAmount = address(this).balance;
if (ETHAmount > 0) {
uint256 amountToWithdraw = ETHAmount.mul(amountPercent).div(100);
(bool success, ) = payable(owner()).call{value: amountToWithdraw}("");
require(success, "ETH transfer failed");
}
}
function withdrawUSDT(uint256 amountPercent) external onlyOwner {
require(amountPercent >= 0 && amountPercent <= 100, "Percent must be between 0 and 100");
uint256 USDTAmount = USDT.balanceOf(address(this));
if (USDTAmount > 0) {
uint256 amountToWithdraw = USDTAmount.mul(amountPercent).div(100);
USDT.transfer(owner(), amountToWithdraw);
}
}
function saleStats() external view returns (
uint256 referPercent,
uint256 salePriceETH,
uint256 salePriceUSDT,
uint256 ETHBalance,
uint256 USDTBalance,
uint256 remainingTokens,
uint256 saleCount,
uint256 currentFeePercent,
address feeReceiverAddress,
uint256 affiliateCommission
) {
return (
_referPercent,
_priceETH,
_priceUSDT,
address(this).balance,
USDT.balanceOf(address(this)),
token.balanceOf(address(this)),
_saleCount,
feePercent,
feeReceiver,
affiliateCommissionPercent
);
}
}
Submitted on: 2025-10-08 09:29:18
Comments
Log in to comment.
No comments yet.