HQ20 / contracts

A set of reusable smart-contracts

Home Page:https://hq20-contracts.netlify.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix Fixidity conversions in ERC20DividendableEth

alcueca opened this issue · comments

I made line-by-line details here: https://github.com/HQ20/contracts/tree/fix/erc20-fixidity

In a nutshell, amounts in wei are actually a fixed point representation, even if most people don't realize. The comma is at decimals().

We should convert wei amounts from a decimals() representation to a Fixidity representation (which uses 24 decimals). That is done with weiAmount.newFixed(this.decimals()).

Conversely, to pass from Fixidity to wei we use fixedAmount.fromFixed(this.decimals()).

When coding ERC20DividendableEth, keep all state variables in Fixidity representation. All wei amounts in functions should be converted to Fixidity immediately. Conversion back to wei should be done at the last possible moment.

And I realize I need to write an article on how to use Fixidity in real life.