trenddapp / lottery

Decentralized Lottery by TrendDapp 💰

Home Page:https://trenddapp.com/dapps/lottery

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

invalid prizePool value for historical lotteries

iparsrc opened this issue · comments

I think the problem is in the claimReward function that calls _transferPrize function. In the _transferPrize function, the _winnerPrize is reduced from prizePool and then it's added to the historical lotteries.

    function claimReward()
        external
        ifCompleted
        randomNumberGenerated
        onlyWinnerOrOwner
    {
        uint256 winnerPrize = prizePool * (winnerPercentage / 100);
        _transferPrize(winnerPrize);
        _addLottery();
        _reset();
        emit ClaimedReward(lotteryID);
    }

    function _transferPrize(uint256 _winnerPrize) private {
        prizePool -= _winnerPrize;
        winner.transfer(_winnerPrize); // transfer the winnerPrize to the winner
        payable(owner()).transfer(prizePool); // transfer the rest of the prizePool to the owner
    }

    function _addLottery() private {
        allLotteries[lotteryID++] = LotteryInfo(
            lotteryID,
            prizePool,
            costPerTicket,
            startingTimestamp,
            closingTimestamp,
            winner,
            randomResult
        );
    }

And please make the startingTimestamp, winnerPercentage and lotteryDuration public :D