Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/number/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ pub fn u256_to_big_decimal(u256: &U256) -> BigDecimal {
BigDecimal::from(BigInt::from(big_uint))
}

/// Converts a `ufixed256x18` value (1e18 fixed-point — e.g. a Balancer `Bfp`
/// normalized weight) to its decimal value: `500000000000000000` ->
/// `0.500000000000000000`.
pub fn ufixed18_to_big_decimal(value: &U256) -> BigDecimal {
BigDecimal::new(u256_to_big_int(value), 18)
}

pub fn u160_to_big_decimal(u160: &U160) -> BigDecimal {
let big_uint = BigUint::from_bytes_be(&u160.to_be_bytes::<20>());
BigDecimal::from(BigInt::from(big_uint))
Expand Down
Loading