Function u256_to_price

Source
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 dedicated Quantity::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 a Quantity with the smaller decimals (clamped to FIXED_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).