APE Price: $0.90 (-9.94%)

Contract Diff Checker

Contract Name:
PooBananas

Contract Source Code:

File 1 of 1 : PooBananas

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Interfaces for the $MPOO token and Golden Banana NFT
interface IMPOO {
    function transfer(address recipient, uint256 amount) external returns (bool);
    function decimals() external view returns (uint8); // Add decimals() function to get decimals
    function balanceOf(address account) external view returns (uint256); // Add balanceOf to check the contract's balance
}
interface IGoldenBanana {
    function transferFrom(address from, address to, uint256 tokenId) external;
    function ownerOf(uint256 tokenId) external view returns (address);
}

contract PooBananas {
    address public owner = 0x4D09C5DfD949470c684E6D537E24C399c075AD40;  // Owner address
    IMPOO public mpooToken = IMPOO(0xAf9DB8640FAFC11c5eF50497b76bD3Fe11541003);  // $MPOO token contract address
    IGoldenBanana public goldenBananaNFT = IGoldenBanana(0x825F5E41FfCbe875D19F51895c814F088Bd45169);  // Golden Banana NFT contract address
    
    uint256[] public nftTokenIds;  // Array to store the token IDs of Golden Banana NFTs
    uint256 public nftCount;  // Total number of NFTs held by the contract

    event Winner(address indexed user, uint256 amountReceived, uint256 nftReceived);
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }

    constructor() {}

    // Receive ETH and automatically handle the lottery logic
    receive() external payable {
        uint256 participantETH = msg.value;

        // Transfer 90% of the funds to the owner
        uint256 amountToOwner = (participantETH * 90) / 100;
        payable(owner).transfer(amountToOwner);

        uint256 chance = uint256(keccak256(abi.encodePacked(block.difficulty, block.timestamp, msg.sender))) % 100;

        // Get the decimals of $MPOO token (usually 18 decimals for most tokens)
        uint8 mpooDecimals = mpooToken.decimals();
        uint256 mpooAmount = 5000 * (10 ** uint256(mpooDecimals));  // Adjust for decimals

        if (chance < 90) {
            // 90% chance to receive $MPOO
            require(mpooToken.transfer(msg.sender, mpooAmount), "Failed to transfer $MPOO");
            emit Winner(msg.sender, mpooAmount, 0);
        } else {
            // 10% chance to receive Golden Banana NFT
            require(nftCount > 0, "No NFTs available in contract");

            // Randomly select an NFT
            uint256 randomIndex = uint256(keccak256(abi.encodePacked(block.difficulty, block.timestamp, msg.sender))) % nftCount;
            uint256 nftTokenId = nftTokenIds[randomIndex];

            // Transfer the randomly selected NFT to the winner
            goldenBananaNFT.transferFrom(owner, msg.sender, nftTokenId);
            
            // Remove the NFT from the array (optional, to prevent re-usage)
            nftTokenIds[randomIndex] = nftTokenIds[nftCount - 1];
            nftTokenIds.pop();
            nftCount--;

            emit Winner(msg.sender, 0, nftTokenId);
        }
    }

    // Withdraw all ETH for the owner
    function withdrawAllETH() external onlyOwner {
        uint256 contractBalance = address(this).balance;
        require(contractBalance > 0, "No ETH to withdraw");
        payable(owner).transfer(contractBalance);
    }

    // Withdraw all $MPOO tokens for the owner
    function withdrawAllMPOO() external onlyOwner {
        uint256 contractBalance = mpooToken.balanceOf(address(this));
        require(contractBalance > 0, "No $MPOO to withdraw");
        require(mpooToken.transfer(owner, contractBalance), "Failed to transfer $MPOO");
    }

    // Deposit funds into the contract by the owner
    function deposit() external payable onlyOwner {}

    // Add NFTs to the contract's collection (only callable by the owner)
    function addNFTs(uint256[] calldata _nftTokenIds) external onlyOwner {
        for (uint256 i = 0; i < _nftTokenIds.length; i++) {
            nftTokenIds.push(_nftTokenIds[i]);
        }
        nftCount += _nftTokenIds.length;
    }

    // Update the NFT token ID to be sent out (optional)
    function updateNFTTokenId(uint256 _newTokenId) external onlyOwner {
        nftTokenIds.push(_newTokenId);
        nftCount++;
    }

    // Fallback function to accept ETH (if send() is used instead of receive())
    fallback() external payable {}
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):