Reflect finance variables?

I have this same question in my topic. I’ve personally tried to reach out to the RFI devs for answers to no avail.

I can understand that _rTotal has a very large number attached. I think it’s supposed to stand for “Reflection Totals”

You can actually see it in one of the functions requirements

function tokenFromReflection(uint256 rAmount) public view returns (uint256){        // no idea what this does
        require(rAmount <= _rTotal, "Amount must be less than total reflections");
        uint256 currentRate = getReflectRate();
        return rAmount.div(currentRate);        // gets the amount of the reflection
    }

I think what it’s doing is somehow calculating the total POSSIBLE reflections that can occur within the token.

However, in another function

function takeReflectFee(uint256 reflectFee, uint256 taxFee) private {
        _rTotal = _rTotal.sub(reflectFee);      // subtracts the fee from the reflect totals
        totalFeeAmount = totalFeeAmount.add(taxFee);    // adds to the toal fee amount
    }

You can see that it’s reducing the rTotal amount. Which is odd to me. Is there a limited number of reflections that can happen per token? Why would that keep getting reduced? It doesn’t make sense to me.

function deliverReflectTokens(uint256 tAmount) public {   
        address sender = _msgSender();          
        require(!isAccountExcludedFromReward[sender],"Excluded addresses cannot call this function");
        (uint256 rAmount, , , , , ) = getTaxAndReflectionValues(tAmount);
        reflectTokensOwned[sender] = reflectTokensOwned[sender].sub(rAmount);
        _rTotal = _rTotal.sub(rAmount);
        totalFeeAmount = totalFeeAmount.add(tAmount);
    }

There is also this function, which isn’t called from within it’s code, but instead it’s called manually from outside the contract.

This doesn’t make a lot of sense to me, how does this all work? I have no clue, only that it “works” as shown from all the clones that use RFI.

If you figure it out I would appreciate you adding me on Discord (in my profile) to explain it to me haha.

I’d also like to state that RFI code was written in a very smelly way. I’ve rewritten part of RFI to reduce the code base. You can reduce their nasty if/else. What I’m trying to say is that if you had the time you could probably rewrite RFI to be way better and to make more logical sense. I will probably end up rewriting RFI in a future project.