//                                                                               
//             @@@@@@@@                                          @@@@@@@@          
//            /@@@@@@@@@                                        @@@@@@@@@,         
//            @@@@@@@@@@&                                      @@@@@@@@@@@         
//           *@@@@@@@@@@@%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%&@@@@@@@@@@@         
//           @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@        
//          .@@@@@@@@*          @@@@@@@@@@@@@@@@@@@@@@@@          /@@@@@@@@        
//          @@@@@#               @@@@@@@@@@@@@@@@@@@@@@               &@@@@@       
//         *@@@@                  /@@@@@@@@@@@@@@@@@@*                 /@@@@       
//      /@@@@@@@                                                        @@@@@@@*   
//    @@@@@@@@@*      @@@@@@@/                            &@@@@@@@      *@@@@@@@@& 
//    @@@@@@@@@       @@@@@@@@                            @@@@@@@@       @@@@@@@@@ 
//   *@@@@@@@@@      .@@@@@@@@                            @@@@@@@@       @@@@@@@@@ 
//   *@@@@@@@@@      *@@@@@@@@                            @@@@@@@@       @@@@@@@@@ 
//    @@@@@@@@@      .@@@@@@@@                            @@@@@@@@       @@@@@@@@@ 
//    @@@@@@@@@       @@@@@@@@                            @@@@@@@@      ,@@@@@@@@@ 
//      @@@@@@@&                                                        @@@@@@@@   
//         /@@@@                   &@@@@@@@@@@@@@@@@#                   @@@@       
//          @@@@@                &@@@@@@@@@@@@@@@@@@@@(               .@@@@%       
//           (@@@@@@            &@@@@@@@@@@@@@@@@@@@@@@(           ,@@@@@@,        
//             ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@           
//                  (@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,                                                                                                                                                                             
// 
//           The #1 Discord trading tool, sniper & wallet - https://discord.gg/membot
//                   https://twitter.com/MembotETH | https://membot.tools
// 

pragma solidity ^0.8.0;

// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */


// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(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 {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

interface IMEMBOT {
    function unblacklist(address) external;
    function blacklistLiquidityPool(address) external;
    function withdrawStuckEth(address) external;
    function withdrawStuckToken(address, address) external;
}

contract MembotBuffer is Ownable {

    address public teamTreasury;

    address public holderRewardsReserve;

    uint256 public teamAllocation = 70;

    IMEMBOT public membotTokenContract;

    constructor(address _teamTreasury, address _holderRewardsReserve) Ownable(msg.sender) {
        teamTreasury = _teamTreasury;
        holderRewardsReserve = _holderRewardsReserve;
    }

    function setMembotTokenContract (address _token) external onlyOwner {
        membotTokenContract = IMEMBOT(_token);
    }

    function changeTeamTreasury(address _teamTreasury) external onlyOwner {
        teamTreasury = _teamTreasury;
    }

    function changeHolderReserve(address _holderRewardsReserve) external onlyOwner {
        holderRewardsReserve = _holderRewardsReserve;
    }

    function changeTeamAllocation(uint256 _teamAllocation) external onlyOwner {
        require(_teamAllocation <= 100, "Cannot be more than 100%");
        teamAllocation = _teamAllocation;
    }

    function withdrawExcessEth() external onlyOwner {
        // Send remaining balance to teamTreasury
        (bool success, ) = teamTreasury.call{value: address(this).balance}("");
        require(success, "Transfer to Team Treasury failed.");
    }

    // Calls main token contract to withdraw any stuck ETH.
    function withdrawStuckEth() external onlyOwner {
        membotTokenContract.withdrawStuckEth(owner());
    }

    // Calls main token contract to withdraw any stuck tokens.
    function withdrawStuckToken(address _token) external onlyOwner {
        membotTokenContract.withdrawStuckToken(_token, owner());
    }

    // Unblacklist any Uniswap V3 LP Pools if we chose to use them in the future.
    function unblacklist(address _accountOrContract) external onlyOwner {
        membotTokenContract.unblacklist(_accountOrContract);
    }

    // Ability to blacklist any Uniswap V3 LP pools.
    function blacklistLiquidityPool(address _contract) external onlyOwner {
        membotTokenContract.blacklistLiquidityPool(_contract);
    }

    receive() external payable {
        unchecked {
        uint256 amountReceived = msg.value;
        //Calculates reward allocation by subtracting the amount allocated to the team
        uint256 rewardAllocation = 100 - teamAllocation;

        (bool success, ) = teamTreasury.call{value: (amountReceived / 100 * teamAllocation)}("");
        require(success, "Transfer to Team Treasury failed");
        (success, ) = holderRewardsReserve.call{value: (amountReceived / 100 * rewardAllocation)}("");
        require(success, "Transfer to Reward Reserve failed");
        }
    }

}