Skip to content

Commit 092eeb8

Browse files
committed
more clippy suggestions
1 parent c86129c commit 092eeb8

File tree

11 files changed

+68
-61
lines changed

11 files changed

+68
-61
lines changed

crates/shared/src/sources/balancer_v2/pool_fetching/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl BalancerPoolFetching for BalancerPoolFetcher {
605605
.push(Gyro3CLPPool::new_unpaused(pool.id, state)),
606606
PoolKind::GyroE(state) => fetched_pools
607607
.gyro_e_pools
608-
.push(GyroEPool::new_unpaused(pool.id, state)),
608+
.push(GyroEPool::new_unpaused(pool.id, *state)),
609609
}
610610
fetched_pools
611611
},

crates/shared/src/sources/balancer_v2/pools/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub enum PoolKind {
3939
Stable(stable::PoolState),
4040
Gyro2CLP(gyro_2clp::PoolState),
4141
Gyro3CLP(gyro_3clp::PoolState),
42-
GyroE(gyro_e::PoolState),
42+
GyroE(Box<gyro_e::PoolState>),
4343
}
4444

4545
macro_rules! impl_from_state {
@@ -56,7 +56,13 @@ impl_from_state!(weighted::PoolState, Weighted);
5656
impl_from_state!(stable::PoolState, Stable);
5757
impl_from_state!(gyro_2clp::PoolState, Gyro2CLP);
5858
impl_from_state!(gyro_3clp::PoolState, Gyro3CLP);
59-
impl_from_state!(gyro_e::PoolState, GyroE);
59+
60+
// Manual implementation for GyroE to use Box
61+
impl From<gyro_e::PoolState> for PoolKind {
62+
fn from(state: gyro_e::PoolState) -> Self {
63+
Self::GyroE(Box::new(state))
64+
}
65+
}
6066

6167
#[derive(Clone, Debug, Eq, PartialEq)]
6268
/// Balancer pool status.

crates/shared/src/sources/balancer_v2/swap/gyro_3clp_math.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn calculate_cubic_starting_point(cubic_terms: &CubicTerms) -> Result<(BigIn
164164
};
165165

166166
let l0 = mul_up_fixed(&lplus, &factor);
167-
let l_lower = mul_up_fixed(&lplus, &*L_VS_LPLUS_MIN);
167+
let l_lower = mul_up_fixed(&lplus, &L_VS_LPLUS_MIN);
168168

169169
Ok((l_lower, l0))
170170
}
@@ -197,7 +197,7 @@ pub fn run_newton_iteration(
197197
}
198198

199199
if iteration >= INVARIANT_MIN_ITERATIONS
200-
&& &delta_abs >= &(&delta_abs_prev / INVARIANT_SHRINKING_FACTOR_PER_STEP)
200+
&& delta_abs >= (&delta_abs_prev / INVARIANT_SHRINKING_FACTOR_PER_STEP)
201201
{
202202
return Ok(root_est);
203203
}
@@ -207,7 +207,7 @@ pub fn run_newton_iteration(
207207
if delta_is_pos {
208208
root_est = &root_est + &delta_abs;
209209
} else {
210-
if &root_est < &delta_abs {
210+
if root_est < delta_abs {
211211
return Err(Error::StableInvariantDidntConverge);
212212
}
213213
let new_root_est = &root_est - &delta_abs;

crates/shared/src/sources/balancer_v2/swap/gyro_e_math.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ pub fn calc_min_aty_a_chix_sq_plus_aty_sq(
830830

831831
/// Solve the quadratic equation for swap calculations
832832
/// Complete implementation matching Python solve_quadratic_swap
833+
#[allow(clippy::too_many_arguments)]
833834
pub fn solve_quadratic_swap(
834835
lambda: &BigInt,
835836
x: &BigInt,
@@ -3021,7 +3022,7 @@ mod tests {
30213022
} else if error_pct < 0.01 {
30223023
// 0.01% tolerance
30233024
println!(" Pass: Good - Error < 0.01%");
3024-
} else if error_pct >= 0.99 && error_pct <= 1.02 {
3025+
} else if (0.99..=1.02).contains(&error_pct) {
30253026
// Expected ~1% difference due to swap fees
30263027
println!(
30273028
" Pass: EXPECTED - ~{:.3}% difference due to 1% swap fees in \
@@ -3084,7 +3085,7 @@ mod tests {
30843085
} else if error_pct < 0.01 {
30853086
// 0.01% tolerance
30863087
println!(" Pass: Good - Error < 0.01%");
3087-
} else if error_pct >= 0.99 && error_pct <= 1.02 {
3088+
} else if (0.99..=1.02).contains(&error_pct) {
30883089
// Expected ~1% difference due to swap fees
30893090
println!(
30903091
" Pass: EXPECTED - ~{:.3}% difference due to 1% swap fees in \

crates/shared/src/sources/balancer_v2/swap/signed_fixed_point.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ impl SBfp {
177177
precision: FixedPointPrecision,
178178
) -> Result<Self, anyhow::Error> {
179179
// Handle negative sign
180-
let (is_negative, s) = if s.starts_with('-') {
181-
(true, &s[1..])
180+
let (is_negative, s) = if let Some(stripped) = s.strip_prefix('-') {
181+
(true, stripped)
182182
} else {
183183
(false, s)
184184
};

crates/shared/src/sources/balancer_v3/pools/gyro_2clp.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ fn pool_state(
110110
let tokens = common
111111
.tokens
112112
.into_iter()
113-
.map(|(address, common_state)| (address, common_state))
114113
.collect();
115114

116115
Ok(Some(PoolState {

crates/shared/src/sources/balancer_v3/pools/gyro_e.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ fn pool_state(
179179
let tokens = common
180180
.tokens
181181
.into_iter()
182-
.map(|(address, common_state)| (address, common_state))
183182
.collect();
184183

185184
Ok(Some(PoolState {

crates/shared/src/sources/balancer_v3/swap/gyro_e_math.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ pub fn calc_min_aty_a_chix_sq_plus_aty_sq(
830830

831831
/// Solve the quadratic equation for swap calculations
832832
/// Complete implementation matching Python solve_quadratic_swap
833+
#[allow(clippy::too_many_arguments)]
833834
pub fn solve_quadratic_swap(
834835
lambda: &BigInt,
835836
x: &BigInt,
@@ -3021,7 +3022,7 @@ mod tests {
30213022
} else if error_pct < 0.01 {
30223023
// 0.01% tolerance
30233024
println!(" Pass: Good - Error < 0.01%");
3024-
} else if error_pct >= 0.99 && error_pct <= 1.02 {
3025+
} else if (0.99..=1.02).contains(&error_pct) {
30253026
// Expected ~1% difference due to swap fees
30263027
println!(
30273028
" Pass: EXPECTED - ~{:.3}% difference due to 1% swap fees in \
@@ -3084,7 +3085,7 @@ mod tests {
30843085
} else if error_pct < 0.01 {
30853086
// 0.01% tolerance
30863087
println!(" Pass: Good - Error < 0.01%");
3087-
} else if error_pct >= 0.99 && error_pct <= 1.02 {
3088+
} else if (0.99..=1.02).contains(&error_pct) {
30883089
// Expected ~1% difference due to swap fees
30893090
println!(
30903091
" Pass: EXPECTED - ~{:.3}% difference due to 1% swap fees in \

crates/shared/src/sources/balancer_v3/swap/mod.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,50 @@ impl BaselineSolvable for QuantAmmPool {
15791579
}
15801580
}
15811581

1582+
/// Extract weights and multipliers from packed arrays.
1583+
/// This matches the getFirstFourWeightsAndMultipliers and
1584+
/// getSecondFourWeightsAndMultipliers pattern from balancer-maths.
1585+
fn extract_weights_and_multipliers(
1586+
first_four: &[I256],
1587+
second_four: &[I256],
1588+
num_tokens: usize,
1589+
) -> Option<(Vec<I256>, Vec<I256>)> {
1590+
let mut weights = Vec::new();
1591+
let mut multipliers = Vec::new();
1592+
1593+
// Process first four tokens (matches balancer-maths
1594+
// getFirstFourWeightsAndMultipliers)
1595+
let first_token_count = std::cmp::min(4, num_tokens);
1596+
for i in 0..first_token_count {
1597+
if i < first_four.len() / 2 {
1598+
weights.push(first_four[i]);
1599+
if i + first_token_count < first_four.len() {
1600+
multipliers.push(first_four[i + first_token_count]);
1601+
} else {
1602+
multipliers.push(I256::zero());
1603+
}
1604+
}
1605+
}
1606+
1607+
// Process remaining tokens if any (matches balancer-maths
1608+
// getSecondFourWeightsAndMultipliers)
1609+
if num_tokens > 4 {
1610+
let remaining_count = num_tokens - 4;
1611+
for i in 0..remaining_count {
1612+
if i < second_four.len() / 2 {
1613+
weights.push(second_four[i]);
1614+
if i + remaining_count < second_four.len() {
1615+
multipliers.push(second_four[i + remaining_count]);
1616+
} else {
1617+
multipliers.push(I256::zero());
1618+
}
1619+
}
1620+
}
1621+
}
1622+
1623+
Some((weights, multipliers))
1624+
}
1625+
15821626
#[cfg(test)]
15831627
mod tests {
15841628
use {super::*, crate::sources::balancer_v3::pool_fetching::CommonPoolState};
@@ -1819,47 +1863,3 @@ mod tests {
18191863
assert_eq!(res_out.unwrap(), amount_in.into());
18201864
}
18211865
}
1822-
1823-
/// Extract weights and multipliers from packed arrays.
1824-
/// This matches the getFirstFourWeightsAndMultipliers and
1825-
/// getSecondFourWeightsAndMultipliers pattern from balancer-maths.
1826-
fn extract_weights_and_multipliers(
1827-
first_four: &[I256],
1828-
second_four: &[I256],
1829-
num_tokens: usize,
1830-
) -> Option<(Vec<I256>, Vec<I256>)> {
1831-
let mut weights = Vec::new();
1832-
let mut multipliers = Vec::new();
1833-
1834-
// Process first four tokens (matches balancer-maths
1835-
// getFirstFourWeightsAndMultipliers)
1836-
let first_token_count = std::cmp::min(4, num_tokens);
1837-
for i in 0..first_token_count {
1838-
if i < first_four.len() / 2 {
1839-
weights.push(first_four[i]);
1840-
if i + first_token_count < first_four.len() {
1841-
multipliers.push(first_four[i + first_token_count]);
1842-
} else {
1843-
multipliers.push(I256::zero());
1844-
}
1845-
}
1846-
}
1847-
1848-
// Process remaining tokens if any (matches balancer-maths
1849-
// getSecondFourWeightsAndMultipliers)
1850-
if num_tokens > 4 {
1851-
let remaining_count = num_tokens - 4;
1852-
for i in 0..remaining_count {
1853-
if i < second_four.len() / 2 {
1854-
weights.push(second_four[i]);
1855-
if i + remaining_count < second_four.len() {
1856-
multipliers.push(second_four[i + remaining_count]);
1857-
} else {
1858-
multipliers.push(I256::zero());
1859-
}
1860-
}
1861-
}
1862-
}
1863-
1864-
Some((weights, multipliers))
1865-
}

crates/shared/src/sources/balancer_v3/swap/signed_fixed_point.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ impl SBfp {
176176
precision: FixedPointPrecision,
177177
) -> Result<Self, anyhow::Error> {
178178
// Handle negative sign
179-
let (is_negative, s) = if s.starts_with('-') {
180-
(true, &s[1..])
179+
let (is_negative, s) = if let Some(stripped) = s.strip_prefix('-') {
180+
(true, stripped)
181181
} else {
182182
(false, s)
183183
};

0 commit comments

Comments
 (0)