...
The ratios are initialized in a way to keep the ROE as close to 1 to limit the rounding loss issues when SUFs or SRPs are truncated.
It is still possible that rounding loss will occur, but is less likely and smaller in impact and deemed acceptable:
User may get different (potentially smaller) number of FIO than they staked if they stake/unstake before any fees were collected.
If all users unstake the tokens, there may not be enough tokens to distribute or some tokens may be left when all tokens are unstaked.
The following model demonstrates such loss. Please note that this is text-only model, due to significant digit limitation of Google Sheets.
For added safety, we should not cast any variables to long doubles or doubles or compute/store ROE in the interim, but instead compute using int-based math with interim variables. See c++ example.
Dev steps
Implement LCTP and LGSRP as above
Implement int-based math for SUF → SRP and SRP → SUF calculation as in c++ example.
Add safety checks:
On unstake, check if enough tokens are left in CTP and if not transfer only what is left in CTP.
On unstake, check if enough srps are left in GSRP and if not deduct only what is left in GSRP.
Consider overflow check on interims.
...