Bake Beans

When you bake your ETH on the dApp, the smart contract deposits it into the TVL (contract). The ETH baked into the TVL will be locked and it will be returned via the "My rewards" section of the dApp. Next, you will receive "beans," which will represent the number of tokens you own. These "beans" will automatically begin your journey toward passive income generation.

Let's analyze the bakeBeans function:

  1. Initialization Check:

    require(initialized);

    This ensures the contract is initialized before proceeding with the rest of the function.

  2. Calculate Eggs Bought:

    uint256 eggsBought = calculateEggBuy(msg.value, (address(this).balance - msg.value));

    This calculates the number of eggs that can be bought with the value of Ether (msg.value) sent to the function, based on the current contract balance minus the sent value.

  3. Apply Bean Tax:

    eggsBought -= beanTax(eggsBought);

    This subtracts a "bean tax" from the eggs bought.

  4. Transfers to Marketing, Treasury, and Team Addresses:

    marketingAdd.transfer((msg.value * 2) / 100);
    treasuryAdd.transfer((msg.value * 5) / 100);
    teamAdd.transfer((msg.value * 1) / 100);

    These lines transfer 2%, 5%, and 1% of the sent Ether to marketing, treasury, and team addresses respectively.

  5. Update Claimed Eggs:

    claimedEggs[msg.sender] += eggsBought;

    This adds the purchased eggs to the claimedEggs of the sender.

  6. Calculate and Update New Miners:

    uint256 eggsUsed = getMyEggs(msg.sender);
    uint256 newMiners = (eggsUsed / EGGS_TO_HATCH_1MINERS);
    hatcheryMiners[msg.sender] += newMiners;
    claimedEggs[msg.sender] = 0;

    This calculates the number of new miners based on the eggs the sender has and updates the sender's miner count. It then resets the sender's claimed eggs to 0.

  7. Referral Handling:

    if (ref == msg.sender) {
        ref = address(0);
    }

    If the sender uses their own address as the referral, it sets the referral to address(0).

  8. Set Referral:

    if (referrals[msg.sender] == address(0) && referrals[msg.sender] != msg.sender) {
        referrals[msg.sender] = ref;
    }

    This sets the sender's referral address if it has not been set yet and is not the sender.

  9. Timestamp Handling:

    if (lastHatch[msg.sender] == 0) {
        lastHatch[msg.sender] = block.timestamp;
    }
    if (lastHatch[referrals[msg.sender]] == 0) {
        lastHatch[referrals[msg.sender]] = block.timestamp;
    }
    if (firstBuy[msg.sender] == 0) {
        firstBuy[msg.sender] = block.timestamp;
    }

    These conditions set the lastHatch and firstBuy timestamps for the sender and their referral if they are not already set.

  10. Update Referrals Miners:

    hatcheryMiners[referrals[msg.sender]] += ((eggsBought / 10) / EGGS_TO_HATCH_1MINERS); 
    claimedEggs[referrals[msg.sender]] = 0;

    This updates the miner count for the sender's referral based on 10% of the eggs bought and resets the referral's claimed eggs to 0.


The referral calculation does not deduct from the buyer's eggs. The referral calculation determines how many new miners the referral receives based on the eggs bought by the buyer. It doesn't directly affect the number of eggs owned by the buyer.

  1. When a buyer purchases eggs, they pay Ether for those eggs.

  2. A portion of the bought eggs is allocated to the buyer, and the rest is used for various purposes like developer fees, marketing, treasury, team, and referral rewards.

  3. In the case of the referral calculation, a percentage of the bought eggs (10% in this case) is allocated to the referral. This allocation does not reduce the number of eggs owned by the buyer. Instead, it creates new miners for the referral based on the allocated eggs.

So, the referral calculation doesn't deduct from the buyer's eggs; it simply allocates a portion of the bought eggs to the referral without affecting the buyer's balance.

**A 10% reward for referral will only be given once. This ensures that the referral reward will not be exploited.

Last updated