Skip to content

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

@ulope

Description

@ulope

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions