pub fn u256_to_price(amount: U256, decimals: u8) -> Result<Price>
Expand description
Convert a U256
amount to [Price
].
- If
decimals == 18
the value represents WEI and we leverage the dedicatedQuantity::from_wei
constructor for loss-less conversion. - For other precisions we fall back to a floating-point conversion identical
to the pre-existing path in
convert_u256_to_f64
and then construct aQuantity
with the smallerdecimals
(clamped toFIXED_PRECISION
).
§Errors
Returns an error when the helper must fall back to the floating-point path
(i.e. decimals != 18
) and the provided amount
cannot be converted to an
f64
(see convert_u256_to_f64
).