fix: Expect decimal during encoding, add assert to test
- The util function was previously expecting a value between 0 and 100, which we felt was a weird UI. - In integration test - make sure we spent all input tokens
This commit is contained in:
@@ -442,7 +442,9 @@ mod tests {
|
||||
},
|
||||
token_in: weth.clone(),
|
||||
token_out: wbtc.clone(),
|
||||
split: 0.5f64,
|
||||
// This represents the remaining 50%, but to avoid any rounding errors we set this to
|
||||
// 0 to signify "the remainder of the WETH value". It should still be very close to 50%
|
||||
split: 0f64,
|
||||
};
|
||||
let swap_dai_usdc = Swap {
|
||||
component: ProtocolComponent {
|
||||
@@ -485,5 +487,6 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let _hex_calldata = encode(&calldata);
|
||||
println!("{}", _hex_calldata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,11 +44,11 @@ pub fn encode_input(selector: &str, mut encoded_args: Vec<u8>) -> Vec<u8> {
|
||||
call_data
|
||||
}
|
||||
|
||||
/// Converts a percentage to a `U24` value. The percentage is a `f64` value between 0 and 100.
|
||||
/// Converts a decimal to a `U24` value. The percentage is a `f64` value between 0 and 1.
|
||||
/// MAX_UINT24 corresponds to 100%.
|
||||
pub fn percentage_to_uint24(percentage: f64) -> U24 {
|
||||
pub fn percentage_to_uint24(decimal: f64) -> U24 {
|
||||
const MAX_UINT24: u32 = 16_777_215; // 2^24 - 1
|
||||
|
||||
let scaled = (percentage / 100.0) * (MAX_UINT24 as f64);
|
||||
let scaled = (decimal / 1.0) * (MAX_UINT24 as f64);
|
||||
U24::from(scaled.round())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user