ITT
ITT copied to clipboard
Ether price value and decimal-places of Token
If Token issuer make Token with decimal places 18 (many real tokens such as Golem GNT use same decimal places with Ether, 18), ether prices used in trade should be multiple of 1 ether (1,2,3,4 ether, ... but not 0.1 ether for 1.000000000000000000 Token exchange)
So I suggest ether price in contract code should be "ether price per 1 base unit of target Token" 1 base unit of target token = 1*10^(decimals) tokens (1.000000000000000000 token)
then, MAXNUM value constraint ("use only 128 bits of uint to prevent mul overflows.") should be reconsidered for integer multiplication and division error.
The base unit is uint 1 and the decimalPlaces
is only utilised by the client. It's up to the client to handle the fractional maths. No divisions are used in the contract at all to avoid rounding errors.
But I think safe division can be performed by restricting token amount and ether price parameter. (restricting that ether price and token aboumt value should have trailing decimal (decimalplaces/2) zeros for example, If decimal-places is 18, token amount value and ether price value should have 9 trailing decimal zeros..
And I hope decimal places of Token might be fixed to constant(=18) same as Ether.
There's simply no need to use fixed-point maths when you have no divides.