About ~uint256(0)

uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 10 * 10**6 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));

What is the value of the MAX and _rTotal constants?
I couldn’t understand the MAX constant :frowning:

2 Likes

Hi, means bitwise negation, so ~uint256(0) = 2**256-1, that is the max value in the type of uint256, and these are just some mathematical calculations, if you do not know, you can deploy the contract to see the final result:

uint256 public constant MAX = ~uint256(0);
uint256 public constant _tTotal = 10 * 10**6 * 10**9;
uint256 public _rTotal = (MAX - (MAX % _tTotal));

So the results are:

MAX = 115792089237316195423570985008687907853269984665640564039457584007913129639935
_tTotal = 10000000000000000
_rTotal = 115792089237316195423570985008687907853269984665640564039457580000000000000000
5 Likes

Where can I check the value of these constants while writing the contract?

for example:

console.log(MAX)
print(MAX)
echo(MAX)

What should I do if I want to see the result as defined as?

I am still in the first hours so I am very inexperienced :slight_smile:
what should be in a developer’s bag? Which tools and what are their functions?

2 Likes

You can use console.log, https://medium.com/nomic-labs-blog/better-solidity-debugging-console-log-is-finally-here-fc66c54f2c4a, but now, this plugin renamed hardhat

2 Likes

thank you so much. Let’s see how the result will be :slight_smile:

2 Likes

3 posts were merged into an existing topic: What does Reflect.Finance code do: _rTotal = (MAX - (MAX % totalSupplyOfToken));

Any special reason why it’s calculated like this:
uint256 public constant _tTotal = 10 * 10**6 * 10**9;

And not like this:
10*24 ?

2 Likes

Maybe token decimals is 9, so use 10**9
initial amount is 10 Million, so use 10 * 10**6

Yeah, of course, you can use 10**24, it depends on you, but you should know what does this number mean exactly.

3 Likes

Yeah.
I figured it out as well and I think I’ll stick with the more common way (10**9 * 10**6 * 10**9)

I seem to forget one 10**9 from my question as well (I’m currently studying a contract (EverRise) with 9 decimals and 1000000000 * 10**6 * 10**9 digits :sweat_smile: :man_facepalming:

I didn’t first realize that the 10**9 was about the decimals, but now it makes more sense.
Thanks for that tip!

2 Likes

What does _rTotal stand for? So like for what is the variable used? What does the number it contains represent?

Read _rTotal as the reflected total. It does not mean anything. Think of it as a symbolic tool to make the reflection work.

So with reflected total, you mean something like the total after calculation of everything? So like the "real" amount of coins or datapackets or smth like that?

For example you can have 0.000000001 coins but if the coin has 9 decimals you then have one of the rTotal? Do i get this right?

tTotal is the true total and you can read it this way. rTotal is the reflected total for making this reflection mechanism work out. I believe the paragraphs in the picture below provides an intuitive explanation.

6 Likes

Where is this piece from? Can I get the full script?

Hello, what is the name of this book plz

1 Like

+1
Really appreciate if you can share with us the name of book and even better if you could suggest more economic books

I tried to google

We first illustrate the idea in Reflect Finance with Magic Kingdom R

pdf's WP's and anything related with reflect.finance, but have no luck.

it would be great if someone can share it.

I just found another explainer, will keep it here just in case:
https://www.keepandshare.com/doc15/24269/reflect-technical-paper-pdf-822k?da=y

~uint256(0) can be simplified as type(uint256).max which means maximum possible value for type uint256.

1 Like

Well _rTotal is simply Total Reflections and _rOwned refers to number of reflection a user owns.
think of this way:
we could set initial _rTotal to 100 to represent 100%
and if your _rOwned value is 10, you own 10% of total reflections.
in the constructor method you see after deployment of the contract, the whole reflections are transfered to the owner of the contract.

_rOwned[_msgSender()] = _rTotal;

using 100 as total reflection has a problem: solidity only supports integers and doesn't support floating point numbers, so we gotta somehow do it another way

If i am right, the reason they set _rTotal to a huge number is to make reflection very accurate and support as much floating points as possible (if i am wrong, correct me), so if you own something like 0.00812301283120398912312836% of reflections, it should work accurately.

I hope i could explain it in a simple way

1 Like

This explanation explains better. Though how the reflection is comouted still seem unclear.