Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions crates/driver/src/boundary/liquidity/balancer/v2/stable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use {
liquidity::{self, balancer},
},
},
ethrpc::alloy::conversions::IntoAlloy,
solver::liquidity::{StablePoolOrder, balancer_v2},
};

Expand All @@ -28,20 +27,20 @@ pub fn to_domain(id: liquidity::Id, pool: StablePoolOrder) -> Result<liquidity::
Ok(balancer::v2::stable::Reserve {
asset: eth::Asset {
token: token.into(),
amount: reserve.balance.into_alloy().into(),
amount: reserve.balance.into(),
},
scale: balancer::v2::ScalingFactor::from_raw(
reserve.scaling_factor.as_uint256().into_alloy(),
reserve.scaling_factor.as_uint256(),
)?,
})
})
.collect::<Result<_>>()?,
)?,
amplification_parameter: balancer::v2::stable::AmplificationParameter::new(
pool.amplification_parameter.factor().into_alloy(),
pool.amplification_parameter.precision().into_alloy(),
pool.amplification_parameter.factor(),
pool.amplification_parameter.precision(),
)?,
fee: balancer::v2::Fee::from_raw(pool.fee.as_uint256().into_alloy()),
fee: balancer::v2::Fee::from_raw(pool.fee.as_uint256()),
}),
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use {
liquidity::{self, balancer},
},
},
ethrpc::alloy::conversions::IntoAlloy,
shared::sources::balancer_v2::pool_fetching::WeightedPoolVersion,
solver::liquidity::{WeightedProductOrder, balancer_v2},
};
Expand All @@ -29,19 +28,19 @@ pub fn to_domain(id: liquidity::Id, pool: WeightedProductOrder) -> Result<liquid
Ok(balancer::v2::weighted::Reserve {
asset: eth::Asset {
token: token.into(),
amount: reserve.common.balance.into_alloy().into(),
amount: reserve.common.balance.into(),
},
weight: balancer::v2::weighted::Weight::from_raw(
reserve.weight.as_uint256().into_alloy(),
reserve.weight.as_uint256(),
),
scale: balancer::v2::ScalingFactor::from_raw(
reserve.common.scaling_factor.as_uint256().into_alloy(),
reserve.common.scaling_factor.as_uint256(),
)?,
})
})
.collect::<Result<_>>()?,
)?,
fee: balancer::v2::Fee::from_raw(pool.fee.as_uint256().into_alloy()),
fee: balancer::v2::Fee::from_raw(pool.fee.as_uint256()),
version: match pool.version {
WeightedPoolVersion::V0 => balancer::v2::weighted::Version::V0,
WeightedPoolVersion::V3Plus => balancer::v2::weighted::Version::V3Plus,
Expand Down
17 changes: 13 additions & 4 deletions crates/shared/src/sources/balancer_v2/graph_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ mod tests {
use {
super::*,
crate::sources::balancer_v2::swap::fixed_point::Bfp,
alloy::primitives::U256,
ethcontract::H256,
maplit::hashmap,
};
Expand Down Expand Up @@ -343,12 +344,16 @@ mod tests {
Token {
address: Address::repeat_byte(0x33),
decimals: 3,
weight: Some(Bfp::from_wei(500_000_000_000_000_000u128.into())),
weight: Some(Bfp::from_wei(U256::from(
500_000_000_000_000_000_u128
))),
},
Token {
address: Address::repeat_byte(0x44),
decimals: 4,
weight: Some(Bfp::from_wei(500_000_000_000_000_000u128.into())),
weight: Some(Bfp::from_wei(U256::from(
500_000_000_000_000_000_u128
))),
},
],
},
Expand Down Expand Up @@ -381,12 +386,16 @@ mod tests {
Token {
address: Address::repeat_byte(0x33),
decimals: 3,
weight: Some(Bfp::from_wei(500_000_000_000_000_000u128.into())),
weight: Some(Bfp::from_wei(U256::from(
500_000_000_000_000_000_u128
))),
},
Token {
address: Address::repeat_byte(0x44),
decimals: 4,
weight: Some(Bfp::from_wei(500_000_000_000_000_000u128.into())),
weight: Some(Bfp::from_wei(U256::from(
500_000_000_000_000_000_u128
))),
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ mod tests {
pools::{MockFactoryIndexing, common::MockPoolInfoFetching, weighted},
swap::fixed_point::Bfp,
},
alloy::primitives::U256,
maplit::{hashmap, hashset},
mockall::predicate::eq,
};
Expand All @@ -256,7 +257,9 @@ mod tests {
let tokens: Vec<Address> = (start..=end + 1)
.map(|i| Address::with_last_byte(i as u8))
.collect();
let weights: Vec<Bfp> = (start..=end + 1).map(|i| Bfp::from_wei(i.into())).collect();
let weights: Vec<Bfp> = (start..=end + 1)
.map(|i| Bfp::from_wei(U256::from(i)))
.collect();
let creation_events: Vec<(PoolCreated, u64)> = (start..=end)
.map(|i| {
(
Expand Down Expand Up @@ -284,8 +287,8 @@ mod tests {
block_created: 0,
},
weights: vec![
Bfp::from_wei(500_000_000_000_000_000u128.into()),
Bfp::from_wei(500_000_000_000_000_000u128.into()),
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
],
},
weighted::PoolInfo {
Expand All @@ -301,9 +304,9 @@ mod tests {
block_created: 0,
},
weights: vec![
Bfp::from_wei(500_000_000_000_000_000u128.into()),
Bfp::from_wei(250_000_000_000_000_000u128.into()),
Bfp::from_wei(250_000_000_000_000_000u128.into()),
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
Bfp::from_wei(U256::from(250_000_000_000_000_000_u128)),
Bfp::from_wei(U256::from(250_000_000_000_000_000_u128)),
],
},
weighted::PoolInfo {
Expand All @@ -315,8 +318,8 @@ mod tests {
block_created: 0,
},
weights: vec![
Bfp::from_wei(500_000_000_000_000_000u128.into()),
Bfp::from_wei(500_000_000_000_000_000u128.into()),
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
Bfp::from_wei(U256::from(500_000_000_000_000_000_u128)),
],
},
],
Expand Down Expand Up @@ -444,7 +447,7 @@ mod tests {
scaling_factors: vec![Bfp::exp10(0)],
block_created: 3,
},
weights: vec![Bfp::from_wei(1337.into())],
weights: vec![Bfp::from_wei(U256::from(1337u64))],
};
let new_creation = PoolCreated {
pool: new_pool.common.address,
Expand Down
64 changes: 30 additions & 34 deletions crates/shared/src/sources/balancer_v2/pools/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use {
},
token_info::TokenInfoFetching,
},
alloy::primitives::Address,
alloy::primitives::{Address, U256},
anyhow::{Context, Result, anyhow, ensure},
contracts::alloy::{BalancerV2BasePool, BalancerV2Vault},
ethcontract::{BlockId, H256, U256},
ethcontract::{BlockId, H256},
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
futures::{FutureExt as _, future::BoxFuture},
std::{collections::BTreeMap, future::Future, sync::Arc},
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<Factory> PoolInfoFetcher<Factory> {
) -> Result<PoolInfo> {
let pool = self.base_pool_at(pool_address);

let pool_id = pool.getPoolId().call().await?.into_legacy();
let pool_id = pool.getPoolId().call().await?;
let tokens = self
.vault
.getPoolTokens(pool_id.0.into())
Expand All @@ -99,7 +99,7 @@ impl<Factory> PoolInfoFetcher<Factory> {
let scaling_factors = self.scaling_factors(&tokens).await?;

Ok(PoolInfo {
id: pool_id,
id: pool_id.into_legacy(),
address: pool_address,
tokens,
scaling_factors,
Expand Down Expand Up @@ -150,7 +150,7 @@ impl<Factory> PoolInfoFetcher<Factory> {
async move {
let (paused, swap_fee, pool_tokens) =
futures::try_join!(fetch_paused, fetch_swap_fee, pool_tokens)?;
let swap_fee = Bfp::from_wei(swap_fee.into_legacy());
let swap_fee = Bfp::from_wei(swap_fee);

let balances = pool_tokens.balances;
let tokens = pool_tokens.tokens.into_iter().collect::<Vec<_>>();
Expand All @@ -160,7 +160,7 @@ impl<Factory> PoolInfoFetcher<Factory> {
(
address,
TokenState {
balance: balance.into_legacy(),
balance,
scaling_factor,
},
)
Expand Down Expand Up @@ -371,7 +371,6 @@ mod tests {
},
anyhow::bail,
contracts::alloy::BalancerV2Vault,
ethcontract::U256,
maplit::{btreemap, hashmap},
mockall::predicate,
std::future,
Expand Down Expand Up @@ -401,7 +400,7 @@ mod tests {
&BalancerV2Vault::BalancerV2Vault::getPoolTokensReturn {
tokens: tokens.to_vec(),
balances: vec![],
lastChangeBlock: U256::zero().into_alloy(),
lastChangeBlock: U256::ZERO,
},
);
asserter.push_success(&get_pool_tokens_response);
Expand Down Expand Up @@ -463,26 +462,23 @@ mod tests {
BalancerV2BasePool::BalancerV2BasePool::getPausedStateCall::abi_encode_returns(
&BalancerV2BasePool::BalancerV2BasePool::getPausedStateReturn {
paused: false,
pauseWindowEndTime: U256::zero().into_alloy(),
bufferPeriodEndTime: U256::zero().into_alloy(),
pauseWindowEndTime: U256::ZERO,
bufferPeriodEndTime: U256::ZERO,
},
);
asserter.push_success(&get_paused_state_response);
let get_swap_fee_percentage_response =
BalancerV2BasePool::BalancerV2BasePool::getSwapFeePercentageCall::abi_encode_returns(
&bfp!("0.003").as_uint256().into_alloy(),
&bfp!("0.003").as_uint256(),
);
asserter.push_success(&get_swap_fee_percentage_response);

let get_pool_tokens_response =
BalancerV2Vault::BalancerV2Vault::getPoolTokensCall::abi_encode_returns(
&BalancerV2Vault::BalancerV2Vault::getPoolTokensReturn {
tokens: tokens.to_vec(),
balances: balances
.iter()
.map(|b| b.as_uint256().into_alloy())
.collect(),
lastChangeBlock: U256::zero().into_alloy(),
balances: balances.iter().map(|b| b.as_uint256()).collect(),
lastChangeBlock: U256::ZERO,
},
);
asserter.push_success(&get_pool_tokens_response);
Expand Down Expand Up @@ -554,24 +550,24 @@ mod tests {
BalancerV2BasePool::BalancerV2BasePool::getPausedStateCall::abi_encode_returns(
&BalancerV2BasePool::BalancerV2BasePool::getPausedStateReturn {
paused: false,
pauseWindowEndTime: U256::zero().into_alloy(),
bufferPeriodEndTime: U256::zero().into_alloy(),
pauseWindowEndTime: U256::ZERO,
bufferPeriodEndTime: U256::ZERO,
},
);
asserter.push_success(&get_paused_state_response);

let get_swap_fee_percentage_response =
BalancerV2BasePool::BalancerV2BasePool::getSwapFeePercentageCall::abi_encode_returns(
&U256::zero().into_alloy(),
&U256::ZERO,
);
asserter.push_success(&get_swap_fee_percentage_response);

let get_pool_tokens_response =
BalancerV2Vault::BalancerV2Vault::getPoolTokensCall::abi_encode_returns(
&BalancerV2Vault::BalancerV2Vault::getPoolTokensReturn {
tokens: vec![Address::repeat_byte(1), Address::repeat_byte(4)],
balances: vec![U256::zero().into_alloy(), U256::zero().into_alloy()],
lastChangeBlock: U256::zero().into_alloy(),
balances: vec![U256::ZERO, U256::ZERO],
lastChangeBlock: U256::ZERO,
},
);
asserter.push_success(&get_pool_tokens_response);
Expand Down Expand Up @@ -619,14 +615,14 @@ mod tests {
BalancerV2BasePool::BalancerV2BasePool::getPausedStateCall::abi_encode_returns(
&BalancerV2BasePool::BalancerV2BasePool::getPausedStateReturn {
paused: false,
pauseWindowEndTime: U256::zero().into_alloy(),
bufferPeriodEndTime: U256::zero().into_alloy(),
pauseWindowEndTime: U256::ZERO,
bufferPeriodEndTime: U256::ZERO,
},
);
asserter.push_success(&get_paused_state_response);
let get_swap_fee_percentage_response =
BalancerV2BasePool::BalancerV2BasePool::getSwapFeePercentageCall::abi_encode_returns(
&swap_fee.as_uint256().into_alloy(),
&swap_fee.as_uint256(),
);
asserter.push_success(&get_swap_fee_percentage_response);

Expand Down Expand Up @@ -679,9 +675,9 @@ mod tests {
balances: pool_state
.tokens
.values()
.map(|token| token.common.balance.into_alloy())
.map(|token| token.common.balance)
.collect(),
lastChangeBlock: U256::zero().into_alloy(),
lastChangeBlock: U256::ZERO,
},
);
asserter.push_success(&get_pool_tokens_response);
Expand Down Expand Up @@ -734,15 +730,15 @@ mod tests {
BalancerV2BasePool::BalancerV2BasePool::getPausedStateCall::abi_encode_returns(
&BalancerV2BasePool::BalancerV2BasePool::getPausedStateReturn {
paused: true,
pauseWindowEndTime: U256::zero().into_alloy(),
bufferPeriodEndTime: U256::zero().into_alloy(),
pauseWindowEndTime: U256::ZERO,
bufferPeriodEndTime: U256::ZERO,
},
);
asserter.push_success(&get_paused_state_response);

let get_swap_fee_percentage_response =
BalancerV2BasePool::BalancerV2BasePool::getSwapFeePercentageCall::abi_encode_returns(
&U256::zero().into_alloy(),
&U256::ZERO,
);
asserter.push_success(&get_swap_fee_percentage_response);

Expand All @@ -751,7 +747,7 @@ mod tests {
&BalancerV2Vault::BalancerV2Vault::getPoolTokensReturn {
tokens: vec![],
balances: vec![],
lastChangeBlock: U256::zero().into_alloy(),
lastChangeBlock: U256::ZERO,
},
);
asserter.push_success(&get_pool_tokens_response);
Expand Down Expand Up @@ -813,15 +809,15 @@ mod tests {
BalancerV2BasePool::BalancerV2BasePool::getPausedStateCall::abi_encode_returns(
&BalancerV2BasePool::BalancerV2BasePool::getPausedStateReturn {
paused: false,
pauseWindowEndTime: U256::zero().into_alloy(),
bufferPeriodEndTime: U256::zero().into_alloy(),
pauseWindowEndTime: U256::ZERO,
bufferPeriodEndTime: U256::ZERO,
},
);
asserter.push_success(&get_paused_state_response);

let get_swap_fee_percentage_response =
BalancerV2BasePool::BalancerV2BasePool::getSwapFeePercentageCall::abi_encode_returns(
&U256::zero().into_alloy(),
&U256::ZERO,
);
asserter.push_success(&get_swap_fee_percentage_response);

Expand All @@ -830,7 +826,7 @@ mod tests {
&BalancerV2Vault::BalancerV2Vault::getPoolTokensReturn {
tokens: vec![],
balances: vec![],
lastChangeBlock: U256::zero().into_alloy(),
lastChangeBlock: U256::ZERO,
},
);
asserter.push_success(&get_pool_tokens_response);
Expand Down
Loading
Loading