0

I am using the transfer function to transfer some balance to an address based on reward scenario.

Now the issue i get is, when comparing the balance of the address as well as contract before and after the transaction, there is a mismatch of value.

            if (_fee > 0) {
                team.transfer(_fee);
                emit PaymentHardware(epochToPay, getHardwareFeePercentage(), _fee);
            }

Here are the balance difference details,On the address

46296754282807731421 - 43953004282807731423 = 2343749999999999998

On the contract address

15624999999999999991 - 13281274457999999993 = 2343725541999999998

So the balance of the account got incremented by 2343749999999999998 (the intended value), but the contract balance only decremented by 2343725541999999998, which is equal to 24458000000003 wei surplus.

I have verified from the event detail about the fee value, the event logs also point to the intended value being transferred. So how is the contract balance being surplus ?

Transaction Receipt for the transaction is

> eth.getTransactionReceipt("0x367d0167c695b21b2a9d99b1632bc6d70cf02defc59ca2354b8b5a80551afd12")
{
  blockHash: "0xe506018af4103aa784ebd70acc32b0b36d597de1fc7aaf22ebebd2a609906c9f",
  blockNumber: 5734,
  contractAddress: null,
  cumulativeGasUsed: 97832,
  from: "0x99dbae4661cc56e307bc6b291ffd4b0b6acaaaa8",
  gasUsed: 97832,
  logs: [{
      address: "0xe4501f4c0c7ff08b6f713977fe28316e30ccc9a2",
      blockHash: "0x8ae448606ebd29b79eb868de108d1c7e5dbb2bfd8a09f0db8d6ba8fdc3ee99c1",
      blockNumber: 5734,
      data: "0x0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000002086ac3510525ffe",
      logIndex: 0,
      removed: false,
      topics: ["0xbbce279f9ed60ffb489a37c1e015bb68c2dc3853842d04a597ce8a805185a5f0"],
      transactionHash: "0x367d0167c695b21b2a9d99b1632bc6d70cf02defc59ca2354b8b5a80551afd12",
      transactionIndex: 0
  }],
  logsBloom: "0x00000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000800000010000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000",
  status: "0x1",
  to: "0xe4501f4c0c7ff08b6f713977fe28316e30ccc9a2",
  transactionHash: "0x367d0167c695b21b2a9d99b1632bc6d70cf02defc59ca2354b8b5a80551afd12",
  transactionIndex: 0
}

Function involved in making the transaction

    //this function is used for equally dividing rewards to missing epochs in which distributeRewards function is not called on time
    function fillRewardsPerEpoch() public {
        require(candidateStatus >= PROPOSED_STATUS);
        uint256 _currentEpoch = currentEpoch();
        if (lastEpochRewardFilled == 0) {
            lastEpochRewardFilled = _currentEpoch.sub(3);
        }
        uint256 _epochToFill = lastEpochRewardFilled.add(1);
        if (_currentEpoch.sub(1) > _epochToFill) {
            //fill rewards for epochs
            uint256 numEpochsWaitingToFill = _currentEpoch.sub(_epochToFill).sub(1);
            uint256 endEpoch = _epochToFill.add(numEpochsWaitingToFill).sub(1);

            uint256 notFilledRewards = address(this).balance.add(TotalRewardWithdrawn).sub(TotalRewardEpochFilled)
            .sub(RemainingStakeAfterResign);
            uint256 rewardsPerEpoch = notFilledRewards.div(numEpochsWaitingToFill);
            uint256 remainingBalance = notFilledRewards;
            for (uint256 i = _epochToFill; i < endEpoch; i++) {
                EpochsReward[i].rewards = rewardsPerEpoch;
                remainingBalance = remainingBalance.sub(rewardsPerEpoch);
                payHardwareFee(i);
            }
            EpochsReward[endEpoch].rewards = remainingBalance;
            lastEpochRewardFilled = endEpoch;
            payHardwareFee(endEpoch);
            TotalRewardEpochFilled = TotalRewardEpochFilled.add(notFilledRewards);
        }
    }

which inturn calls

    function payHardwareFee(uint256 epochToPay) private returns (uint256, uint256) {
        uint256 _reward = EpochsReward[epochToPay].rewards;
        uint256 _feeAndReferral = 0;
        if (lastEpochHWPayout < epochToPay && _reward > 0) {
            //hardware reward fee has not been paid
            uint256 _fee = getHardwareFee(_reward);
            address payable team = teamAddress();

            if (_fee > 0) {
                team.transfer(_fee);
                emit PaymentHardware(epochToPay, getHardwareFeePercentage(), _fee);
            }

            uint256 _refBonus = getRefBonus(_reward);
            if (_refBonus > 0) {
                referralAddress.transfer(_refBonus);
                emit PaymentRef(epochToPay, getRefBonusPercentage(), _refBonus);
            }

            EpochsReward[epochToPay].actualRewards = _reward.sub(_fee).sub(_refBonus);
            TotalRewardWithdrawn = TotalRewardWithdrawn.add(_fee).add(_refBonus);
            _feeAndReferral = _fee.add(_refBonus);
        }
        if (lastEpochHWPayout < epochToPay) lastEpochHWPayout = epochToPay;
        return (_feeAndReferral, EpochsReward[epochToPay].actualRewards);
    }

in this last function the transfer solidity function is being called.

1
  • 1
    Comments are not for extended discussion; this conversation has been moved to chat. – eth Oct 16 '20 at 21:45

Your Answer

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

Browse other questions tagged or ask your own question.