What does Reflect.Finance code do: _rTotal = (MAX - (MAX % totalSupplyOfToken));

In reflect code they start by making

uint256 private totalSupplyOfToken = 1 * 10**9 * 10**9;
then
uint256 private _rTotal = (MAX - (MAX % totalSupplyOfToken));

What exactly is rTotal? When calculating it, it gives an extremely large number. I can understand that it’s supposed to stand for reflection total, but why is that different than the total supply? What am I missing about the conversion? I have a feeling it has to do with the way ethereum looks at the total supply rather than a human does.

Thanks

2 Likes

Hi @Yoshiko,

Welcome to the community :wave:

I suggest asking the Reflect.Finance team. I am not familiar with the project nor the mechanism it uses.

I assume this is the contract:

@Skyge hey Skyge, what does rTotal actually represent in this situation. I understand that the total supply is just that, the total token supply, but what is rTotal trying to show here? Does it mean realTotal? As in the real token supply, combined with decimals?

Thanks.

1 Like

Hey, I am not sure, maybe you can ask the original writer.

I think this is the Maximum divisor, for example, if MAX = 123 and _tTotal = 5, so

_rTotal = (MAX - (MAX % _tTotal));
=>> _rTotal = (123 - (123 % 5)) = 120

I hope I made myself clear.

1 Like

Thanks Skyge! Yeah I’m having a hard time figuring out why exactly they did that in RFI code. I can understand the math, but why is another story haha.

I will probably end up figuring out why it’s exactly doing that after I test deploy and start messing with reflect fees and LP swaps.

Sorry to the OP for bumping this thread, but it’s relevant to figuring out what that code actually does, not just the MAX part.

4 Likes

Hi @Yoshiko,

I moved your replies under this topic.

1 Like

Thanks abcoathup.

I tried to get in touch with the RFI team, but to no avail.

When reading through the code it looks like it really does stand for “total reflections”.
Later on in the code it has a requirement

function tokenFromReflection(uint256 rAmount) public view returns (uint256){
        require(rAmount <= _rTotal, "Amount must be less than total reflections");
        uint256 currentRate = getReflectRate();
        return rAmount.div(currentRate);
    }

But this begs the question of why does _rTotal start out extremely large? Does it mean the Total Possible Reflections?

3 Likes

Hi @Yoshiko,

Sorry I can’t help you with this. I don’t know anything about the protocol or why they use the numbers that they use.

_rTotal: 115792089237316195423570985008687907853269984665640564039457580000000000000000

_tTotal: 10000000000000000

MAX: 115792089237316195423570985008687907853269984665640564039457584007913129639935

I would see if there is a community that you can ask?

2 Likes

Do you know the answer yet? I wonder like you

1 Like

Hi there, welcome to the forums.

Nope, but it the code works, reflection tokens are split between all holders of the token. Perhaps in the future there will be a standardized way to take a tax of a transaction and split it among all holders.

1 Like

Why is reflection tokens equal to (MAX - (MAX% _tTotal)), which is very valuable?

1 Like

Not sure, if you could, could you try to ask in RFI Telegram? I tried but got no response. It would help a lot of people if you got an answer from them.

2 Likes

So I’m not the only one who is confused as hell about this contract which turns out SafeMoon.sol also cloned. My understanding is it’s keeping a ratio between tTotal 1E24 and the difference with MAXuInt24 rTotal because of burning and redistribution.

They can’t just loop through every owned address to .add(redistributionToken) because that would go over the gas limit and pay crazy amount of gas fee.

That said, it’s super confusing and I can’t tell the exact logic what’s happening. If anyone ever figures out, please share.

3 Likes

Also another thing after you deploy the contract is in the constructor, the address deployed will own all of rTotal. So does that mean the Devs secretly hold a lot of tokens and not revealed in the blockchain?

1 Like

Yes, when the contract is deployed (safemoon clones) the tokens go directly to the holder by default. Then the dev usually does dxSale or locked liquidity.

1 Like

but rTotal is not supplyTotal (tTotal). rTotal is maxuint256 with last 1E24 0. So even if dev burns half of tTotal it’s still a large amount of token left from rTotal?

1 Like

tTotal is used to compute the real supply, the Reflections Owned is the way RFI protocol handles their tokenomics.

Basically _rOwned is your supply, but as the reflection amount.

The dev’s choice of what to do with the tokens is up to him. SafeMoon had 1 quadrillion which is kind of absurd to me.

1 Like

Take a look at this blog: https://wd666.medium.com/what-the-hell-is-rtotal-and-ttotal-4e2ec90466f7
hope it helps

3 Likes

hi all - this is a great post thanks for sharing I had the same questions as i was working through the contract today.

I also had another question along similar lines. in the code below the _tOwned[account]=0. If you include an account to participate in rewards - why would we be setting the owned amount to zero?

  function includeInReward(address account) external onlyOwner() {
        require(_isExcluded[account], "Account is already excluded");
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_excluded[i] == account) {
                _excluded[i] = _excluded[_excluded.length - 1];
                **_tOwned[account] = 0;**
                _isExcluded[account] = false;
                _excluded.pop();
                break;
            }
        }
    }

Because when it is included, you are now using the variable, _rOwned[account] to track the amount they own.

Check out what happens when you excludeFromReward. The reverse happens. You are now using _tOwned when it is excluded.

    function excludeFromReward(address account) public onlyOwner() {
        // require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.');
        require(!_isExcluded[account], "Account is already excluded");
        if(_rOwned[account] > 0) {
            _tOwned[account] = tokenFromReflection(_rOwned[account]);
        }
        _isExcluded[account] = true;
        _excluded.push(account);
    }

    function includeInReward(address account) external onlyOwner() {
        require(_isExcluded[account], "Account is already excluded");
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_excluded[i] == account) {
                _excluded[i] = _excluded[_excluded.length - 1];
                _tOwned[account] = 0;
                _isExcluded[account] = false;
                _excluded.pop();
                break;
            }
        }
    }