Skip to content

Commit c86129c

Browse files
committed
added clippy suggestions
1 parent 527dd8f commit c86129c

File tree

12 files changed

+108
-139
lines changed

12 files changed

+108
-139
lines changed

crates/driver/src/boundary/liquidity/balancer/v3/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async fn init_liquidity(
134134
block_retriever: Arc<dyn BlockRetrieving>,
135135
config: &infra::liquidity::config::BalancerV3,
136136
) -> Result<impl LiquidityCollecting + use<>> {
137-
let web3 = boundary::web3(eth);
137+
let web3 = eth.web3().clone();
138138

139139
// Create Balancer V3 contracts configuration
140140
let contracts = BalancerContracts {

crates/driver/src/boundary/liquidity/erc4626.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{
3-
boundary::{self, Result},
3+
boundary::Result,
44
domain::{eth, liquidity},
55
infra::blockchain::Ethereum,
66
},
@@ -40,7 +40,7 @@ pub async fn maybe_collector(eth: &Ethereum) -> AnyResult<Vec<Box<dyn LiquidityC
4040
let config_dir = chain_to_config_dir(&chain);
4141
let primary_path = format!("configs/{}/erc4626.toml", config_dir);
4242
let fallback_path = format!("../{}", primary_path);
43-
let web3 = boundary::web3(eth);
43+
let web3 = eth.web3().clone();
4444
let settlement = eth.contracts().settlement().clone();
4545
let registry: Erc4626Registry = match shared::sources::erc4626::registry::registry_from_file(
4646
std::path::Path::new(&primary_path),

crates/driver/src/infra/solver/dto/auction.rs

Lines changed: 87 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -356,46 +356,48 @@ pub fn new(
356356
)
357357
}
358358
liquidity::Kind::BalancerV2GyroE(pool) => {
359-
solvers_dto::auction::Liquidity::GyroE(solvers_dto::auction::GyroEPool {
360-
id: liquidity.id.0.to_string(),
361-
address: pool.id.address().into(),
362-
balancer_pool_id: pool.id.into(),
363-
gas_estimate: liquidity.gas.into(),
364-
tokens: pool
365-
.reserves
366-
.iter()
367-
.map(|r| {
368-
(
369-
r.asset.token.into(),
370-
solvers_dto::auction::GyroEReserve {
371-
balance: r.asset.amount.into(),
372-
scaling_factor: scaling_factor_to_decimal(r.scale),
373-
},
374-
)
375-
})
376-
.collect(),
377-
fee: fee_to_decimal(pool.fee),
378-
version: match pool.version {
379-
liquidity::balancer::v2::gyro_e::Version::V1 => {
380-
solvers_dto::auction::GyroEVersion::V1
381-
}
359+
solvers_dto::auction::Liquidity::GyroE(Box::new(
360+
solvers_dto::auction::GyroEPool {
361+
id: liquidity.id.0.to_string(),
362+
address: pool.id.address().into(),
363+
balancer_pool_id: pool.id.into(),
364+
gas_estimate: liquidity.gas.into(),
365+
tokens: pool
366+
.reserves
367+
.iter()
368+
.map(|r| {
369+
(
370+
r.asset.token.into(),
371+
solvers_dto::auction::GyroEReserve {
372+
balance: r.asset.amount.into(),
373+
scaling_factor: scaling_factor_to_decimal(r.scale),
374+
},
375+
)
376+
})
377+
.collect(),
378+
fee: fee_to_decimal(pool.fee),
379+
version: match pool.version {
380+
liquidity::balancer::v2::gyro_e::Version::V1 => {
381+
solvers_dto::auction::GyroEVersion::V1
382+
}
383+
},
384+
// Convert all Gyro E-CLP static parameters to BigDecimal
385+
params_alpha: signed_fixed_point_to_decimal(pool.params_alpha),
386+
params_beta: signed_fixed_point_to_decimal(pool.params_beta),
387+
params_c: signed_fixed_point_to_decimal(pool.params_c),
388+
params_s: signed_fixed_point_to_decimal(pool.params_s),
389+
params_lambda: signed_fixed_point_to_decimal(pool.params_lambda),
390+
tau_alpha_x: signed_fixed_point_to_decimal(pool.tau_alpha_x),
391+
tau_alpha_y: signed_fixed_point_to_decimal(pool.tau_alpha_y),
392+
tau_beta_x: signed_fixed_point_to_decimal(pool.tau_beta_x),
393+
tau_beta_y: signed_fixed_point_to_decimal(pool.tau_beta_y),
394+
u: signed_fixed_point_to_decimal(pool.u),
395+
v: signed_fixed_point_to_decimal(pool.v),
396+
w: signed_fixed_point_to_decimal(pool.w),
397+
z: signed_fixed_point_to_decimal(pool.z),
398+
d_sq: signed_fixed_point_to_decimal(pool.d_sq),
382399
},
383-
// Convert all Gyro E-CLP static parameters to BigDecimal
384-
params_alpha: signed_fixed_point_to_decimal(pool.params_alpha),
385-
params_beta: signed_fixed_point_to_decimal(pool.params_beta),
386-
params_c: signed_fixed_point_to_decimal(pool.params_c),
387-
params_s: signed_fixed_point_to_decimal(pool.params_s),
388-
params_lambda: signed_fixed_point_to_decimal(pool.params_lambda),
389-
tau_alpha_x: signed_fixed_point_to_decimal(pool.tau_alpha_x),
390-
tau_alpha_y: signed_fixed_point_to_decimal(pool.tau_alpha_y),
391-
tau_beta_x: signed_fixed_point_to_decimal(pool.tau_beta_x),
392-
tau_beta_y: signed_fixed_point_to_decimal(pool.tau_beta_y),
393-
u: signed_fixed_point_to_decimal(pool.u),
394-
v: signed_fixed_point_to_decimal(pool.v),
395-
w: signed_fixed_point_to_decimal(pool.w),
396-
z: signed_fixed_point_to_decimal(pool.z),
397-
d_sq: signed_fixed_point_to_decimal(pool.d_sq),
398-
})
400+
))
399401
}
400402
liquidity::Kind::BalancerV2Gyro2CLP(pool) => {
401403
solvers_dto::auction::Liquidity::Gyro2CLP(
@@ -463,49 +465,53 @@ pub fn new(
463465
)
464466
}
465467
liquidity::Kind::BalancerV3GyroE(pool) => {
466-
solvers_dto::auction::Liquidity::GyroE(solvers_dto::auction::GyroEPool {
467-
id: liquidity.id.0.to_string(),
468-
address: pool.id.address().into(),
469-
balancer_pool_id: {
470-
let pool_id_h160: eth::H160 = pool.id.into();
471-
pool_id_h160.into()
472-
},
473-
gas_estimate: liquidity.gas.into(),
474-
tokens: pool
475-
.reserves
476-
.iter()
477-
.map(|r| {
478-
(
479-
r.asset.token.into(),
480-
solvers_dto::auction::GyroEReserve {
481-
balance: r.asset.amount.into(),
482-
scaling_factor: scaling_factor_to_decimal_v3(r.scale),
483-
},
484-
)
485-
})
486-
.collect(),
487-
fee: fee_to_decimal_v3(pool.fee),
488-
version: match pool.version {
489-
liquidity::balancer::v3::gyro_e::Version::V1 => {
490-
solvers_dto::auction::GyroEVersion::V1
491-
}
468+
solvers_dto::auction::Liquidity::GyroE(Box::new(
469+
solvers_dto::auction::GyroEPool {
470+
id: liquidity.id.0.to_string(),
471+
address: pool.id.address().into(),
472+
balancer_pool_id: {
473+
let pool_id_h160: eth::H160 = pool.id.into();
474+
pool_id_h160.into()
475+
},
476+
gas_estimate: liquidity.gas.into(),
477+
tokens: pool
478+
.reserves
479+
.iter()
480+
.map(|r| {
481+
(
482+
r.asset.token.into(),
483+
solvers_dto::auction::GyroEReserve {
484+
balance: r.asset.amount.into(),
485+
scaling_factor: scaling_factor_to_decimal_v3(
486+
r.scale,
487+
),
488+
},
489+
)
490+
})
491+
.collect(),
492+
fee: fee_to_decimal_v3(pool.fee),
493+
version: match pool.version {
494+
liquidity::balancer::v3::gyro_e::Version::V1 => {
495+
solvers_dto::auction::GyroEVersion::V1
496+
}
497+
},
498+
// Convert all Gyro E-CLP static parameters to BigDecimal
499+
params_alpha: signed_fixed_point_to_decimal_v3(pool.params_alpha),
500+
params_beta: signed_fixed_point_to_decimal_v3(pool.params_beta),
501+
params_c: signed_fixed_point_to_decimal_v3(pool.params_c),
502+
params_s: signed_fixed_point_to_decimal_v3(pool.params_s),
503+
params_lambda: signed_fixed_point_to_decimal_v3(pool.params_lambda),
504+
tau_alpha_x: signed_fixed_point_to_decimal_v3(pool.tau_alpha_x),
505+
tau_alpha_y: signed_fixed_point_to_decimal_v3(pool.tau_alpha_y),
506+
tau_beta_x: signed_fixed_point_to_decimal_v3(pool.tau_beta_x),
507+
tau_beta_y: signed_fixed_point_to_decimal_v3(pool.tau_beta_y),
508+
u: signed_fixed_point_to_decimal_v3(pool.u),
509+
v: signed_fixed_point_to_decimal_v3(pool.v),
510+
w: signed_fixed_point_to_decimal_v3(pool.w),
511+
z: signed_fixed_point_to_decimal_v3(pool.z),
512+
d_sq: signed_fixed_point_to_decimal_v3(pool.d_sq),
492513
},
493-
// Convert all Gyro E-CLP static parameters to BigDecimal
494-
params_alpha: signed_fixed_point_to_decimal_v3(pool.params_alpha),
495-
params_beta: signed_fixed_point_to_decimal_v3(pool.params_beta),
496-
params_c: signed_fixed_point_to_decimal_v3(pool.params_c),
497-
params_s: signed_fixed_point_to_decimal_v3(pool.params_s),
498-
params_lambda: signed_fixed_point_to_decimal_v3(pool.params_lambda),
499-
tau_alpha_x: signed_fixed_point_to_decimal_v3(pool.tau_alpha_x),
500-
tau_alpha_y: signed_fixed_point_to_decimal_v3(pool.tau_alpha_y),
501-
tau_beta_x: signed_fixed_point_to_decimal_v3(pool.tau_beta_x),
502-
tau_beta_y: signed_fixed_point_to_decimal_v3(pool.tau_beta_y),
503-
u: signed_fixed_point_to_decimal_v3(pool.u),
504-
v: signed_fixed_point_to_decimal_v3(pool.v),
505-
w: signed_fixed_point_to_decimal_v3(pool.w),
506-
z: signed_fixed_point_to_decimal_v3(pool.z),
507-
d_sq: signed_fixed_point_to_decimal_v3(pool.d_sq),
508-
})
514+
))
509515
}
510516
liquidity::Kind::BalancerV3Gyro2CLP(pool) => {
511517
solvers_dto::auction::Liquidity::Gyro2CLP(

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ fn pool_state(
101101
) -> BoxFuture<'static, Result<Option<PoolState>>> {
102102
async move {
103103
let common = common.await;
104-
let tokens = common
105-
.tokens
106-
.into_iter()
107-
.map(|(address, common_state)| (address, common_state))
108-
.collect();
104+
let tokens = common.tokens.into_iter().collect();
109105

110106
Ok(Some(PoolState {
111107
tokens,

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ fn pool_state(
8686
) -> BoxFuture<'static, Result<Option<PoolState>>> {
8787
async move {
8888
let common = common.await;
89-
let tokens = common
90-
.tokens
91-
.into_iter()
92-
.map(|(address, common_state)| (address, common_state))
93-
.collect();
89+
let tokens = common.tokens.into_iter().collect();
9490

9591
Ok(Some(PoolState {
9692
tokens,

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ fn pool_state(
176176
) -> BoxFuture<'static, Result<Option<PoolState>>> {
177177
async move {
178178
let common = common.await;
179-
let tokens = common
180-
.tokens
181-
.into_iter()
182-
.map(|(address, common_state)| (address, common_state))
183-
.collect();
179+
let tokens = common.tokens.into_iter().collect();
184180

185181
Ok(Some(PoolState {
186182
tokens,

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ static WAD: LazyLock<BigInt> = LazyLock::new(|| BigInt::from(1_000_000_000_000_0
1919
// Official constants from Gyro3CLPMath.sol
2020
static MAX_BALANCES: LazyLock<BigInt> =
2121
LazyLock::new(|| BigInt::from(1_000_000_000_000_000_000_000_000_000_000_u128)); // 1e29
22-
static MIN_ROOT_3_ALPHA: LazyLock<BigInt> =
23-
LazyLock::new(|| BigInt::from(158_740_105_196_819_970_u64)); // 0.15874010519681997e18
24-
static MAX_ROOT_3_ALPHA: LazyLock<BigInt> =
25-
LazyLock::new(|| BigInt::from(999_966_665_555_493_800_u64)); // 0.9999666655554938e18
2622
static L_THRESHOLD_SIMPLE_NUMERICS: LazyLock<BigInt> =
2723
LazyLock::new(|| BigInt::from(20_000_000_000_000_000_000_000_000_000_000_u128)); // 2e31
2824
static L_MAX: LazyLock<BigInt> =

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ const DERIVED_DSQ_NORM_ACCURACY_XP: u128 = 100_000_000_000_000_000_000_000; // 1
3838
const MAX_BALANCES: u128 = 100_000_000_000_000_000_000_000_000_000_000_000; // 1e34
3939
const MAX_INVARIANT: u128 = 3_000_000_000_000_000_000_000_000_000_000_000_000; // 3e37
4040

41-
// Invariant ratio limits
42-
const MIN_INVARIANT_RATIO: u64 = 600_000_000_000_000_000; // 60e16 (60%)
43-
const MAX_INVARIANT_RATIO: u64 = 5_000_000_000_000_000_000; // 500e16 (500%)
44-
4541
// Constants for sqrt function - precomputed square roots
4642
const SQRT_1E_NEG_1: u64 = 316227766016837933;
4743
const SQRT_1E_NEG_3: u64 = 31622776601683793;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ const DERIVED_DSQ_NORM_ACCURACY_XP: u128 = 100_000_000_000_000_000_000_000; // 1
3838
const MAX_BALANCES: u128 = 100_000_000_000_000_000_000_000_000_000_000_000; // 1e34
3939
const MAX_INVARIANT: u128 = 3_000_000_000_000_000_000_000_000_000_000_000_000; // 3e37
4040

41-
// Invariant ratio limits
42-
const MIN_INVARIANT_RATIO: u64 = 600_000_000_000_000_000; // 60e16 (60%)
43-
const MAX_INVARIANT_RATIO: u64 = 5_000_000_000_000_000_000; // 500e16 (500%)
44-
4541
// Constants for sqrt function - precomputed square roots
4642
const SQRT_1E_NEG_1: u64 = 316227766016837933;
4743
const SQRT_1E_NEG_3: u64 = 31622776601683793;

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn compute_virtual_balances_updating_price_ratio(
176176
current_fourth_root_price_ratio.mul_down(current_fourth_root_price_ratio)?;
177177

178178
// Determine which token is undervalued (rarer)
179-
let (balance_undervalued, balance_overvalued, last_undervalued, last_overvalued) =
179+
let (balance_undervalued, _balance_overvalued, last_undervalued, last_overvalued) =
180180
if is_pool_above_center {
181181
(
182182
balances_scaled18[0],
@@ -244,17 +244,14 @@ fn compute_virtual_balances_updating_price_range(
244244
virtual_balance_b,
245245
)?)?;
246246

247-
let (mut v_undervalued, mut v_overvalued, b_undervalued, b_overvalued) = if is_pool_above_center
248-
{
247+
let (mut v_overvalued, b_undervalued, b_overvalued) = if is_pool_above_center {
249248
(
250-
virtual_balance_a,
251249
virtual_balance_b,
252250
balances_scaled18[0],
253251
balances_scaled18[1],
254252
)
255253
} else {
256254
(
257-
virtual_balance_b,
258255
virtual_balance_a,
259256
balances_scaled18[1],
260257
balances_scaled18[0],
@@ -277,7 +274,7 @@ fn compute_virtual_balances_updating_price_range(
277274
.sub(Bfp::one())?
278275
.mul_down(v_overvalued)?
279276
.sub(b_overvalued)?;
280-
v_undervalued = Bfp::from_wei(
277+
let v_undervalued = Bfp::from_wei(
281278
big_int_to_u256(&(va_num36 / u256_to_big_int(&va_den.as_uint256())))
282279
.map_err(|_| Error::MulOverflow)?,
283280
);
@@ -304,12 +301,7 @@ fn compute_price_range(
304301
virtual_balance_a: Bfp,
305302
virtual_balance_b: Bfp,
306303
) -> Result<(Bfp, Bfp), Error> {
307-
let invariant = compute_invariant(
308-
balances_scaled18,
309-
virtual_balance_a,
310-
virtual_balance_b,
311-
Rounding::Down,
312-
)?;
304+
let invariant = compute_invariant(balances_scaled18, virtual_balance_a, virtual_balance_b)?;
313305
// minPrice = Vb^2 / invariant (single-step integer division to match TS/Py)
314306
let vb_big: BigInt = u256_to_big_int(&virtual_balance_b.as_uint256());
315307
let inv_big: BigInt = u256_to_big_int(&invariant);
@@ -373,24 +365,14 @@ fn compute_centeredness(
373365
}
374366
}
375367

376-
#[derive(Clone, Copy, Debug)]
377-
enum Rounding {
378-
Down,
379-
Up,
380-
}
381-
382368
fn compute_invariant(
383369
balances_scaled18: &[Bfp; 2],
384370
virtual_balance_a: Bfp,
385371
virtual_balance_b: Bfp,
386-
rounding: Rounding,
387372
) -> Result<U256, Error> {
388373
let a = balances_scaled18[0].add(virtual_balance_a)?;
389374
let b = balances_scaled18[1].add(virtual_balance_b)?;
390-
let prod = match rounding {
391-
Rounding::Down => a.mul_down(b)?,
392-
Rounding::Up => a.mul_up(b)?,
393-
};
375+
let prod = a.mul_down(b)?;
394376
Ok(prod.as_uint256())
395377
}
396378

0 commit comments

Comments
 (0)