I've noticed that a lot of tokens that implement reflections come from safemoon. And I was curious about how safemoon did reflections. I expected to find a for loop somewhere where they are adding to each account's balance, but I did not find anything like that. Instead I foud _rOwned and _tOwned. I kept researching and I came across RFI the contract that started reflections (correct me if I am wrong). But even still I did not really understand how the accounts recieve more tokens? I found their reflect function. (in safemoon its called deliver)
function deliver(uint256 tAmount) public {
address sender = _msgSender();
require(!_isExcluded[sender], "Excluded addresses cannot call this function");
(uint256 rAmount,,,,,) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rTotal = _rTotal.sub(rAmount);
_tFeeTotal = _tFeeTotal.add(tAmount);
}
But after finding this I only had more questions than anserws. Who is calling this function? Why is it not used anywhere in the source code? Another function I found that was just as confusing was reflectionFromToken()
function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount,,,,,) = _getValues(tAmount);
return rAmount;
} else {
(,uint256 rTransferAmount,,,,) = _getValues(tAmount);
return rTransferAmount;
}
}
Once again where is the function being called? What is it even for? Thanks for the help!