UptownResearch / pyTokenSpike

intial work on pyTokens
0 stars 0 forks source link

Fixed point math should respect the number of decimals of the underlying tokens. #13

Open aniemerg opened 4 years ago

aniemerg commented 4 years ago

The existing pyToken math assumes that the underlying token includes 18 decimals. It provides for a "short" and "long" fixed point type, where short is 18 decimals and long is an increased precision type with 27 decimals.

The ERC20 standard permits ERC20 tokens to specify their own number of decimals. This issue is resolved when the pyToken contracts "short" and "long" types reflect the number of decimals of the underlying token , so that the level of precision reflects the choices of the underlying token. The various math functions should also continue to work, of course.

aniemerg commented 4 years ago

Since the collateral and underlying may have different numbers of decimals, they probably need their own "short" and "long" types? This seems straightforward.

More complicated, and something I'm not sure about, is what to do when calculating quantities that use both collateral and the underlying. The answer may depend on the particular quantity being calculated.