diff --git a/packages/injective-math/src/fp_decimal/mod.rs b/packages/injective-math/src/fp_decimal/mod.rs index 40c2bbcf..86ca54e4 100644 --- a/packages/injective-math/src/fp_decimal/mod.rs +++ b/packages/injective-math/src/fp_decimal/mod.rs @@ -72,6 +72,12 @@ impl From for FPDecimal { } } +impl From for Uint256 { + fn from(value: FPDecimal) -> Self { + value.to_u256() + } +} + impl From for FPDecimal { fn from(x: Uint256) -> FPDecimal { FPDecimal::from_str(&x.to_string()).unwrap() @@ -456,6 +462,18 @@ mod tests { assert_eq!(uint256, Uint256::from(12345u64)); } + #[test] + fn test_into_u256() { + let fp_decimal: Uint256 = FPDecimal { + num: U256::from(12345u64), + sign: 1, // Assuming it's always positive + } + .into(); + let u256 = Uint256::from(12345u64); + + assert_eq!(u256, fp_decimal) + } + #[test] fn into_uint256_floor() { let fp_decimal = FPDecimal {