Skip to content

Commit b164ff1

Browse files
committed
Remove IntoAlloy/IntoLegacy conversions for Balancer V2 pools
Removes unnecessary type conversions between ethcontract and alloy types in Balancer V2 pool code. The conversions are no longer needed as the codebase migrates to native alloy types. Updates affected areas: - Remove IntoAlloy/IntoLegacy trait usage for U256, addresses, and pool data - Convert ethcontract::U256 to alloy::primitives::U256 in tests and implementations - Simplify type conversions in stable, weighted, composable stable, and liquidity bootstrapping pools Signed-off-by: Aryan Godara <[email protected]>
1 parent 38a3173 commit b164ff1

File tree

18 files changed

+363
-323
lines changed

18 files changed

+363
-323
lines changed

crates/driver/src/boundary/liquidity/balancer/v2/stable.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use {
66
liquidity::{self, balancer},
77
},
88
},
9-
ethrpc::alloy::conversions::IntoAlloy,
109
solver::liquidity::{StablePoolOrder, balancer_v2},
1110
};
1211

@@ -28,20 +27,20 @@ pub fn to_domain(id: liquidity::Id, pool: StablePoolOrder) -> Result<liquidity::
2827
Ok(balancer::v2::stable::Reserve {
2928
asset: eth::Asset {
3029
token: token.into(),
31-
amount: reserve.balance.into_alloy().into(),
30+
amount: reserve.balance.into(),
3231
},
3332
scale: balancer::v2::ScalingFactor::from_raw(
34-
reserve.scaling_factor.as_uint256().into_alloy(),
33+
reserve.scaling_factor.as_uint256(),
3534
)?,
3635
})
3736
})
3837
.collect::<Result<_>>()?,
3938
)?,
4039
amplification_parameter: balancer::v2::stable::AmplificationParameter::new(
41-
pool.amplification_parameter.factor().into_alloy(),
42-
pool.amplification_parameter.precision().into_alloy(),
40+
pool.amplification_parameter.factor(),
41+
pool.amplification_parameter.precision(),
4342
)?,
44-
fee: balancer::v2::Fee::from_raw(pool.fee.as_uint256().into_alloy()),
43+
fee: balancer::v2::Fee::from_raw(pool.fee.as_uint256()),
4544
}),
4645
})
4746
}

crates/driver/src/boundary/liquidity/balancer/v2/weighted.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use {
66
liquidity::{self, balancer},
77
},
88
},
9-
ethrpc::alloy::conversions::IntoAlloy,
109
shared::sources::balancer_v2::pool_fetching::WeightedPoolVersion,
1110
solver::liquidity::{WeightedProductOrder, balancer_v2},
1211
};
@@ -29,19 +28,19 @@ pub fn to_domain(id: liquidity::Id, pool: WeightedProductOrder) -> Result<liquid
2928
Ok(balancer::v2::weighted::Reserve {
3029
asset: eth::Asset {
3130
token: token.into(),
32-
amount: reserve.common.balance.into_alloy().into(),
31+
amount: reserve.common.balance.into(),
3332
},
3433
weight: balancer::v2::weighted::Weight::from_raw(
35-
reserve.weight.as_uint256().into_alloy(),
34+
reserve.weight.as_uint256(),
3635
),
3736
scale: balancer::v2::ScalingFactor::from_raw(
38-
reserve.common.scaling_factor.as_uint256().into_alloy(),
37+
reserve.common.scaling_factor.as_uint256(),
3938
)?,
4039
})
4140
})
4241
.collect::<Result<_>>()?,
4342
)?,
44-
fee: balancer::v2::Fee::from_raw(pool.fee.as_uint256().into_alloy()),
43+
fee: balancer::v2::Fee::from_raw(pool.fee.as_uint256()),
4544
version: match pool.version {
4645
WeightedPoolVersion::V0 => balancer::v2::weighted::Version::V0,
4746
WeightedPoolVersion::V3Plus => balancer::v2::weighted::Version::V3Plus,

crates/shared/src/sources/balancer_v2/graph_api.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ mod tests {
245245
use {
246246
super::*,
247247
crate::sources::balancer_v2::swap::fixed_point::Bfp,
248+
alloy::primitives::U256,
248249
ethcontract::H256,
249250
maplit::hashmap,
250251
};
@@ -343,12 +344,16 @@ mod tests {
343344
Token {
344345
address: Address::repeat_byte(0x33),
345346
decimals: 3,
346-
weight: Some(Bfp::from_wei(500_000_000_000_000_000u128.into())),
347+
weight: Some(Bfp::from_wei(U256::from(
348+
500_000_000_000_000_000_u128
349+
))),
347350
},
348351
Token {
349352
address: Address::repeat_byte(0x44),
350353
decimals: 4,
351-
weight: Some(Bfp::from_wei(500_000_000_000_000_000u128.into())),
354+
weight: Some(Bfp::from_wei(U256::from(
355+
500_000_000_000_000_000_u128
356+
))),
352357
},
353358
],
354359
},
@@ -381,12 +386,16 @@ mod tests {
381386
Token {
382387
address: Address::repeat_byte(0x33),
383388
decimals: 3,
384-
weight: Some(Bfp::from_wei(500_000_000_000_000_000u128.into())),
389+
weight: Some(Bfp::from_wei(U256::from(
390+
500_000_000_000_000_000_u128
391+
))),
385392
},
386393
Token {
387394
address: Address::repeat_byte(0x44),
388395
decimals: 4,
389-
weight: Some(Bfp::from_wei(500_000_000_000_000_000u128.into())),
396+
weight: Some(Bfp::from_wei(U256::from(
397+
500_000_000_000_000_000_u128
398+
))),
390399
},
391400
],
392401
},

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ mod tests {
233233
pools::{MockFactoryIndexing, common::MockPoolInfoFetching, weighted},
234234
swap::fixed_point::Bfp,
235235
},
236+
alloy::primitives::U256,
236237
maplit::{hashmap, hashset},
237238
mockall::predicate::eq,
238239
};
@@ -256,7 +257,9 @@ mod tests {
256257
let tokens: Vec<Address> = (start..=end + 1)
257258
.map(|i| Address::with_last_byte(i as u8))
258259
.collect();
259-
let weights: Vec<Bfp> = (start..=end + 1).map(|i| Bfp::from_wei(i.into())).collect();
260+
let weights: Vec<Bfp> = (start..=end + 1)
261+
.map(|i| Bfp::from_wei(U256::from(i)))
262+
.collect();
260263
let creation_events: Vec<(PoolCreated, u64)> = (start..=end)
261264
.map(|i| {
262265
(
@@ -284,8 +287,8 @@ mod tests {
284287
block_created: 0,
285288
},
286289
weights: vec![
287-
Bfp::from_wei(500_000_000_000_000_000u128.into()),
288-
Bfp::from_wei(500_000_000_000_000_000u128.into()),
290+
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
291+
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
289292
],
290293
},
291294
weighted::PoolInfo {
@@ -301,9 +304,9 @@ mod tests {
301304
block_created: 0,
302305
},
303306
weights: vec![
304-
Bfp::from_wei(500_000_000_000_000_000u128.into()),
305-
Bfp::from_wei(250_000_000_000_000_000u128.into()),
306-
Bfp::from_wei(250_000_000_000_000_000u128.into()),
307+
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
308+
Bfp::from_wei(U256::from(250_000_000_000_000_000_u128)),
309+
Bfp::from_wei(U256::from(250_000_000_000_000_000_u128)),
307310
],
308311
},
309312
weighted::PoolInfo {
@@ -315,8 +318,8 @@ mod tests {
315318
block_created: 0,
316319
},
317320
weights: vec![
318-
Bfp::from_wei(500_000_000_000_000_000u128.into()),
319-
Bfp::from_wei(500_000_000_000_000_000u128.into()),
321+
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
322+
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
320323
],
321324
},
322325
],
@@ -444,7 +447,7 @@ mod tests {
444447
scaling_factors: vec![Bfp::exp10(0)],
445448
block_created: 3,
446449
},
447-
weights: vec![Bfp::from_wei(1337.into())],
450+
weights: vec![Bfp::from_wei(U256::from(1337u64))],
448451
};
449452
let new_creation = PoolCreated {
450453
pool: new_pool.common.address,

0 commit comments

Comments
 (0)