0

I met some issue when editing a template code. I have a function payForCommission and I hope it will auto execute when another function invest been called.

Here is the following invest function:

function invest(address referer, uint units) external {
         require(enabled, "Pool Not Enabled");
         require(units >= minUnits, "Less than Min Units");
         require(units <= maxUnits, "Over than Max Units");

        uint userid = userids[msg.sender];
        if (userid == 0) {
            totalUsers += 1;
            userid = totalUsers;
            userids[msg.sender] = userid;
            emit UserMsg(userid, "Joined", 0);
        }

        User storage user = users[userid];
        if (user.account == address(0)) {
            user.account = msg.sender;
            user.checkpoint = block.timestamp;
        }

        if (user.referer == address(0) && referer != address(0)) {
            if (users[userids[referer]].totalDeposit > 0 && referer != msg.sender && user.totalDeposit == 0) {
                user.referer = referer;
                users[userids[referer]].partners.push(userid);
                processLevelUpdate(referer, msg.sender);

                address parent = referer;
                for (uint i = 0; i < 5; i++) {
                    if (parent == address(0)) break;
                    levels[userids[parent]].team += 1;
                    parent = users[userids[parent]].referer;
                }
            }
        }

        payForCommission(referer, value); //THE DECLARATION ERROR IS HERE
        processDeposit(units);
        payReferral(referer, units);
    }

So here is the following payForCommission function:

function payForCommission(address referer, uint value) private returns (uint){
            address upline = referer;
    
            uint totalRefOut;
            for (uint i = 0; i < referRate.length; i++) {
                uint uplineId = userids[upline];
                if (uplineId == 0) break;
                if (upline != address(0) && levels[uplineId].level > i) {
                        uint bonus = value * referRate[i] / 1000;
                        totalRefOut = totalRefOut + bonus;
                        token.safeTransfer(upline, bonus);
                        //                    emit PayBonus(upline, bonus);
                        emit UserMsg(uplineId, "RefBonus", bonus);
                        users[uplineId].totalBonus += bonus;
                        if (i == 0) {
                            users[uplineId].directBonus += bonus;
                        }
                    
                    upline = users[uplineId].referer;
                } else break;
            }
    
            for (uint i = 0; i < team.length; i++) {
                uint bonus = value * teamRate / 1000 / team.length;
                totalRefOut += bonus;
                token.safeTransfer(team[i], bonus / team.length);
                //            emit PayBonus(team[i], bonus);
                emit UserMsg(userids[team[i]], "TeamBonus", bonus);
                users[userids[team[i]]].totalBonus += bonus;
                users[userids[team[i]]].teamBonus += bonus;
            }
            
            totalBonus += totalRefOut;
            uint marketingOut = value * marketingFee / 1000;
            token.safeTransfer(marketingWallet, marketingOut);
    
            uint commi = totalRefOut + marketingOut;
            emit Commission(commi);
            return commi;
        }

The error show like this:

enter image description here

1 Answer 1

1

You didn't declare value variable and consequently you cannot pass it to payForCommission() function. You must to declare a value variable like this:

uint value = [VALUE_VARIABLE];

And then you can pass it into payForCommission() function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.