-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Problem Definition
The raiden_libs.service_registry
CLI utility uses this code to format token amounts:
raiden-services/src/raiden_libs/service_registry.py
Lines 207 to 212 in d1d126e
def format_token_amount(amount: float) -> str: | |
if amount == 0: | |
return f"0 {symbol}" | |
amount /= 10 ** decimals | |
show_dec = max(-floor(log10(abs(amount)) + 1) + min_sig_figures, 0) | |
return ("{:." + str(show_dec) + "f} {}").format(amount, symbol) |
The problem is that this rounds down small decimal fractions for typical tokens with 18 decimals.
Example that was encountered by our community RSB provider Hymner while extending his service registration:
Actual token value required: 842.048535677596500000
Value displayed: 842
In this specific case that lead to too few tokens to be available in the wallet and the registration failing with the unintentionally hilarious message: You have 842 RDN but need 842 RDN.
Proposed solution
I'd argue that rounding is probably always the wrong thing to do here.
If at all then only rounding up would produce still inaccurate but at least not non-working results.