Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required deposit value is rounded down in service registry script #1021

Open
ulope opened this issue Jun 4, 2021 · 0 comments
Open

Required deposit value is rounded down in service registry script #1021

ulope opened this issue Jun 4, 2021 · 0 comments

Comments

@ulope
Copy link
Contributor

ulope commented Jun 4, 2021

Problem Definition

The raiden_libs.service_registry CLI utility uses this code to format token amounts:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant