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
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions crates/driver/src/boundary/liquidity/balancer/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use {
BalancerV2WeightedPoolFactory,
BalancerV2WeightedPoolFactoryV3,
},
ethrpc::block_stream::{BlockRetrieving, CurrentBlockWatcher},
ethrpc::{
alloy::conversions::IntoAlloy,
block_stream::{BlockRetrieving, CurrentBlockWatcher},
},
shared::{
http_solver::model::TokenAmount,
sources::balancer_v2::{
Expand All @@ -27,7 +30,7 @@ use {
},
solver::{
interactions::allowances::Allowances,
liquidity::{balancer_v2, balancer_v2::BalancerV2Liquidity},
liquidity::balancer_v2::{self, BalancerV2Liquidity},
liquidity_collector::{BackgroundInitLiquiditySource, LiquidityCollecting},
},
std::sync::Arc,
Expand All @@ -48,7 +51,7 @@ fn to_interaction(
receiver: &eth::Address,
) -> eth::Interaction {
let handler = balancer_v2::SettlementHandler::new(
pool.id.into(),
pool.id.0.into_alloy(),
// Note that this code assumes `receiver == sender`. This assumption is
// also baked into the Balancer V2 logic in the `shared` crate, so to
// change this assumption, we would need to change it there as well.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
liquidity::{self, balancer},
},
},
ethrpc::alloy::conversions::IntoAlloy,
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
solver::liquidity::{StablePoolOrder, balancer_v2},
};

Expand Down Expand Up @@ -62,6 +62,7 @@ fn pool_id(pool: &StablePoolOrder) -> balancer::v2::Id {
.downcast_ref::<balancer_v2::SettlementHandler>()
.expect("downcast balancer settlement handler")
.pool_id()
.into_legacy()
.into()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
liquidity::{self, balancer},
},
},
ethrpc::alloy::conversions::IntoAlloy,
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
shared::sources::balancer_v2::pool_fetching::WeightedPoolVersion,
solver::liquidity::{WeightedProductOrder, balancer_v2},
};
Expand Down Expand Up @@ -66,6 +66,7 @@ fn pool_id(pool: &WeightedProductOrder) -> balancer::v2::Id {
.downcast_ref::<balancer_v2::SettlementHandler>()
.expect("downcast balancer settlement handler")
.pool_id()
.into_legacy()
.into()
}

Expand Down
6 changes: 4 additions & 2 deletions crates/driver/src/boundary/liquidity/zeroex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ pub fn to_domain(
let domain = zeroex::LimitOrder {
order,
fillable: Amounts {
maker: limit_order.sell_amount.as_u128(),
taker: limit_order.buy_amount.as_u128(),
maker: u128::try_from(limit_order.sell_amount)
.expect("value should be lower than u128::MAX"),
taker: u128::try_from(limit_order.buy_amount)
.expect("value should be lower than u128::MAX"),
},
zeroex: handler.zeroex.clone(),
};
Expand Down
2 changes: 0 additions & 2 deletions crates/solver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ anyhow = { workspace = true }
arc-swap = { workspace = true }
async-trait = { workspace = true }
contracts = { workspace = true }
ethcontract = { workspace = true }
ethrpc = { workspace = true }
futures = { workspace = true }
observe = { workspace = true }
Expand All @@ -27,7 +26,6 @@ maplit = { workspace = true }
model = { workspace = true }
num = { workspace = true }
number = { workspace = true }
primitive-types = { workspace = true }
prometheus = { workspace = true }
prometheus-metric-storage = { workspace = true }
serde_json = { workspace = true }
Expand Down
14 changes: 6 additions & 8 deletions crates/solver/src/interactions/balancer_v2.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use {
alloy::{
primitives::{Address, U256},
primitives::{Address, B256, Bytes, U256},
sol_types::SolCall,
},
contracts::alloy::BalancerV2Vault::{BalancerV2Vault::swapCall, IVault},
ethcontract::{Bytes, H256},
ethrpc::alloy::conversions::IntoAlloy,
shared::{
http_solver::model::TokenAmount,
interaction::{EncodedInteraction, Interaction},
Expand All @@ -17,10 +15,10 @@ use {
pub struct BalancerSwapGivenOutInteraction {
pub settlement: Address,
pub vault: Address,
pub pool_id: H256,
pub pool_id: B256,
pub asset_in_max: TokenAmount,
pub asset_out: TokenAmount,
pub user_data: Bytes<Vec<u8>>,
pub user_data: Bytes,
}

/// An impossibly distant future timestamp. Note that we use `0x80000...00`
Expand All @@ -31,12 +29,12 @@ pub static NEVER: LazyLock<U256> = LazyLock::new(|| U256::from(1) << 255);
impl BalancerSwapGivenOutInteraction {
pub fn encode_swap(&self) -> EncodedInteraction {
let single_swap = IVault::SingleSwap {
poolId: self.pool_id.into_alloy(),
poolId: self.pool_id,
kind: 1, // GivenOut
assetIn: self.asset_in_max.token,
assetOut: self.asset_out.token,
amount: self.asset_out.amount,
userData: self.user_data.clone().into_alloy(),
userData: self.user_data.clone(),
};
let funds = IVault::FundManagement {
sender: self.settlement,
Expand Down Expand Up @@ -73,7 +71,7 @@ mod tests {
let interaction = BalancerSwapGivenOutInteraction {
settlement: Address::from_slice(&[0x02; 20]),
vault: vault_address,
pool_id: H256([0x03; 32]),
pool_id: B256::repeat_byte(0x03),
asset_in_max: TokenAmount::new(
Address::repeat_byte(0x04),
alloy::primitives::U256::from(1_337_000_000_000_000_000_000u128),
Expand Down
30 changes: 16 additions & 14 deletions crates/solver/src/interactions/uniswap_v2.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use {
alloy::{primitives::Address, sol_types::SolCall},
alloy::{
primitives::{Address, U256},
sol_types::SolCall,
},
contracts::alloy::IUniswapLikeRouter,
ethrpc::alloy::conversions::IntoAlloy,
primitive_types::{H160, U256},
shared::interaction::{EncodedInteraction, Interaction},
};

Expand All @@ -12,8 +13,8 @@ pub struct UniswapInteraction {
pub settlement: Address,
pub amount_out: U256,
pub amount_in_max: U256,
pub token_in: H160,
pub token_out: H160,
pub token_in: Address,
pub token_out: Address,
}

impl Interaction for UniswapInteraction {
Expand All @@ -25,9 +26,9 @@ impl Interaction for UniswapInteraction {
impl UniswapInteraction {
pub fn encode_swap(&self) -> EncodedInteraction {
let calldata = IUniswapLikeRouter::IUniswapLikeRouter::swapTokensForExactTokensCall {
amountOut: self.amount_out.into_alloy(),
amountInMax: self.amount_in_max.into_alloy(),
path: vec![self.token_in.into_alloy(), self.token_out.into_alloy()],
amountOut: self.amount_out,
amountInMax: self.amount_in_max,
path: vec![self.token_in, self.token_out],
to: self.settlement,
deadline: ::alloy::primitives::U256::MAX,
}
Expand All @@ -50,19 +51,19 @@ mod tests {
fn encode_uniswap_call() {
let amount_out = 5;
let amount_in_max = 6;
let token_in = H160::from_low_u64_be(7);
let token_in = Address::with_last_byte(7);
let token_out = 8;
let payout_to = 9u8;

let router_address = Address::from(&[1u8; 20]);
let settlement = H160::from_low_u64_be(payout_to as u64).into_alloy();
let settlement = Address::with_last_byte(payout_to);
let interaction = UniswapInteraction {
router: router_address,
settlement,
amount_out: amount_out.into(),
amount_in_max: amount_in_max.into(),
amount_out: U256::from(amount_out),
amount_in_max: U256::from(amount_in_max),
token_in,
token_out: H160::from_low_u64_be(token_out as u64),
token_out: Address::with_last_byte(token_out),
};
let swap_call = interaction.encode();

Expand All @@ -73,14 +74,15 @@ mod tests {
let path_offset = 160;
let path_size = 2;
let deadline = [0xffu8; 32];

assert_eq!(call[0..4], swap_signature);
assert_eq!(call[4..36], u8_as_32_bytes_be(amount_out));
assert_eq!(call[36..68], u8_as_32_bytes_be(amount_in_max));
assert_eq!(call[68..100], u8_as_32_bytes_be(path_offset));
assert_eq!(call[100..132], u8_as_32_bytes_be(payout_to));
assert_eq!(call[132..164], deadline);
assert_eq!(call[164..196], u8_as_32_bytes_be(path_size));
assert_eq!(&call[208..228], token_in.as_fixed_bytes());
assert_eq!(&call[208..228], &token_in);
assert_eq!(call[228..260], u8_as_32_bytes_be(token_out));
}
}
27 changes: 14 additions & 13 deletions crates/solver/src/liquidity/balancer_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use {
liquidity_collector::LiquidityCollecting,
settlement::SettlementEncoder,
},
alloy::primitives::Address,
alloy::primitives::{Address, B256},
anyhow::Result,
ethcontract::H256,
ethrpc::alloy::conversions::IntoAlloy,
model::TokenPair,
shared::{
ethrpc::Web3,
Expand Down Expand Up @@ -83,7 +83,7 @@ impl BalancerV2Liquidity {
fee: pool.common.swap_fee,
version: pool.version,
settlement_handling: Arc::new(SettlementHandler {
pool_id: pool.common.id,
pool_id: pool.common.id.into_alloy(),
inner: inner.clone(),
}),
})
Expand All @@ -97,7 +97,7 @@ impl BalancerV2Liquidity {
fee: pool.common.swap_fee,
amplification_parameter: pool.amplification_parameter,
settlement_handling: Arc::new(SettlementHandler {
pool_id: pool.common.id,
pool_id: pool.common.id.into_alloy(),
inner: inner.clone(),
}),
})
Expand Down Expand Up @@ -128,7 +128,7 @@ impl LiquidityCollecting for BalancerV2Liquidity {
}

pub struct SettlementHandler {
pool_id: H256,
pool_id: B256,
inner: Arc<Inner>,
}

Expand All @@ -139,7 +139,7 @@ struct Inner {
}

impl SettlementHandler {
pub fn new(pool_id: H256, settlement: Address, vault: Address, allowances: Allowances) -> Self {
pub fn new(pool_id: B256, settlement: Address, vault: Address, allowances: Allowances) -> Self {
SettlementHandler {
pool_id,
inner: Arc::new(Inner {
Expand All @@ -154,7 +154,7 @@ impl SettlementHandler {
&self.inner.vault
}

pub fn pool_id(&self) -> H256 {
pub fn pool_id(&self) -> B256 {
self.pool_id
}

Expand Down Expand Up @@ -229,6 +229,7 @@ mod tests {
crate::interactions::allowances::{Approval, MockAllowanceManaging},
alloy::primitives::U256,
contracts::alloy::BalancerV2Vault,
ethrpc::alloy::conversions::IntoLegacy,
maplit::{btreemap, hashmap, hashset},
mockall::predicate::*,
model::TokenPair,
Expand Down Expand Up @@ -276,7 +277,7 @@ mod tests {
let weighted_pools = vec![
WeightedPool {
common: CommonPoolState {
id: H256([0x90; 32]),
id: B256::repeat_byte(0x90).into_legacy(),
address: Address::repeat_byte(0x90),
swap_fee: "0.002".parse().unwrap(),
paused: true,
Expand Down Expand Up @@ -308,7 +309,7 @@ mod tests {
},
WeightedPool {
common: CommonPoolState {
id: H256([0x91; 32]),
id: B256::repeat_byte(0x91).into_legacy(),
address: Address::repeat_byte(0x91),
swap_fee: "0.001".parse().unwrap(),
paused: true,
Expand All @@ -335,7 +336,7 @@ mod tests {

let stable_pools = vec![StablePool {
common: CommonPoolState {
id: H256([0x92; 32]),
id: B256::repeat_byte(0x92).into_legacy(),
address: Address::repeat_byte(0x92),
swap_fee: "0.002".parse().unwrap(),
paused: true,
Expand Down Expand Up @@ -473,7 +474,7 @@ mod tests {
),
});
let handler = SettlementHandler {
pool_id: H256([0x90; 32]),
pool_id: B256::repeat_byte(0x90),
inner,
};

Expand Down Expand Up @@ -513,7 +514,7 @@ mod tests {
BalancerSwapGivenOutInteraction {
settlement,
vault: *vault.address(),
pool_id: H256([0x90; 32]),
pool_id: B256::repeat_byte(0x90),
asset_in_max: TokenAmount::new(Address::repeat_byte(0x70), U256::from(10)),
asset_out: TokenAmount::new(Address::repeat_byte(0x71), U256::from(11)),
user_data: Default::default(),
Expand All @@ -522,7 +523,7 @@ mod tests {
BalancerSwapGivenOutInteraction {
settlement,
vault: *vault.address(),
pool_id: H256([0x90; 32]),
pool_id: B256::repeat_byte(0x90),
asset_in_max: TokenAmount::new(Address::repeat_byte(0x71), U256::from(12)),
asset_out: TokenAmount::new(Address::repeat_byte(0x72), U256::from(13)),
user_data: Default::default(),
Expand Down
Loading
Loading