Eat Beans

The Eat Beans function is simply the reason why all investors have joined this project. This is where your hard-earned ETH is returned to you. The quantity received will vary based on the day you choose to eat, as explained further in the whitepaper. The only transaction fees, aside from the "hasbean" tax and bean tax, will be the usual gas rates that apply to the BLAST network.

The major change we made is that it will reset all mapping except for the referral mapping of the user once the Eat Beans function is called. So if the user Eat Beans this means he is withdrawing the funds that were invested plus gains. If the user wants to enter again he has to Bake Beans again.

We have also implemented the hasBean Tax which will be explained here

Let's break down the eatBeans function:

  1. Initialization and Investment Checks:

    require(initialized, "Contract not initialized");
    require(firstBuy[msg.sender] > 0, "Must be Invested");

    The function first checks if the contract is initialized and if the user has previously made an investment (i.e., firstBuy is greater than 0).

  2. Calculate Egg Value and Fee:

    uint256 hasEggs = getMyEggs(msg.sender);
    uint256 eggValue = calculateEggSell(hasEggs);
    uint256 fee = beanTax(eggValue);

    It retrieves the number of eggs the user has, calculates the Ether value of these eggs if sold, and determines the associated fee.

  3. Determine Additional Tax and Split:

    uint256 taxRate = hasBeanTaxed(msg.sender);
    uint256 taxAmount = (eggValue * taxRate) / 100;
    
    uint256 marketingTax = (taxAmount * 40) / 100;
    uint256 treasuryTax = (taxAmount * 50) / 100;
    uint256 teamTax = (taxAmount * 10) / 100;

    It calculates an additional tax based on the user's specific tax rate. This tax is then split into portions for marketing, treasury, and the team.

  4. Adjust Egg Value and Update User State:

    eggValue -= taxAmount;
    claimedEggs[msg.sender] = 0;
    hatcheryMiners[msg.sender] = 0;
    firstBuy[msg.sender] = 0;
    lastHatch[msg.sender] = 0;
    marketEggs += hasEggs;

    The total egg value is reduced by the calculated tax amount. The user's claimed eggs, miners, firstBuy, and lastHatch are reset, and the user's eggs are added to the market pool.

  5. Transfer Marketing, Treasury, and Team Taxes:

    marketingAdd.transfer(marketingTax);
    treasuryAdd.transfer(treasuryTax);
    teamAdd.transfer(teamTax);

    The function then transfers the respective portions of the additional tax to the marketing, treasury, and team addresses.

  6. Deduct Standard Fee and Transfer:

    eggValue -= fee;
    marketingAdd.transfer((eggValue * 2) / 100);
    treasuryAdd.transfer((eggValue * 5) / 100);
    teamAdd.transfer((eggValue * 1) / 100);

    After deducting the initial fee, the function transfers 2%, 5%, and 1% of the remaining egg value to the marketing, treasury, and team addresses respectively.

  7. Transfer Remaining Ether to User:

    payable(msg.sender).transfer(eggValue);

    Finally, the remaining Ether (after all deductions) is transferred to the user.

We have implemented the "HasBean" Tax that Baked Beans 2.0 used. This adds a layer of protection and gamification for Bake Beans: Reborn. **Please read about "HasBeanTax" to avoid loss of funds. Refer to the HasBeanTax document here

Last updated