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

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ tikv-jemallocator = { version = "0.6", features = ["unprefixed_malloc_on_support
jemalloc_pprof = { version = "0.8", features = ["symbolize"] }
ethcontract-generate = { git = "https://github.com/cowprotocol/ethcontract-rs", rev = "8e112a88988040cde6110379ee6d1be768a13244", default-features = false }
ethcontract-mock = { git = "https://github.com/cowprotocol/ethcontract-rs", rev = "8e112a88988040cde6110379ee6d1be768a13244", default-features = false }
ethereum-types = "0.14.1"
flate2 = "1.0.30"
futures = "0.3.30"
gas-estimation = { git = "https://github.com/cowprotocol/gas-estimation", tag = "v0.7.3", features = ["web3_", "tokio_"] }
Expand Down
3 changes: 1 addition & 2 deletions crates/autopilot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "autopilot"
path = "src/main.rs"

[dependencies]
alloy = { workspace = true }
alloy = { workspace = true, features = ["rand"] }
app-data = { workspace = true }
bytes-hex = { workspace = true } # may get marked as unused but it's used with serde
anyhow = { workspace = true }
Expand Down Expand Up @@ -45,7 +45,6 @@ model = { workspace = true }
num = { workspace = true }
number = { workspace = true }
order-validation = { workspace = true }
primitive-types = { workspace = true }
prometheus = { workspace = true }
prometheus-metric-storage = { workspace = true }
rand = { workspace = true }
Expand Down
37 changes: 19 additions & 18 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use {
crate::{domain::fee::FeeFactor, infra},
alloy::primitives::Address,
alloy::primitives::{Address, U256},
anyhow::{Context, anyhow, ensure},
chrono::{DateTime, Utc},
clap::ValueEnum,
primitive_types::{H160, U256},
shared::{
arguments::{display_list, display_option, display_secret_option},
bad_token::token_owner_finder,
Expand Down Expand Up @@ -509,7 +508,7 @@ pub enum Account {
/// AWS KMS is used to retrieve the solver public key
Kms(Arn),
/// Solver public key
Address(H160),
Address(Address),
}

// Wrapper type for AWS ARN identifiers
Expand Down Expand Up @@ -546,14 +545,16 @@ impl FromStr for Solver {
let url: Url = url.parse()?;
let submission_account = match Arn::from_str(parts[2]) {
Ok(value) => Account::Kms(value),
_ => Account::Address(H160::from_str(parts[2]).context("failed to parse submission")?),
_ => {
Account::Address(Address::from_str(parts[2]).context("failed to parse submission")?)
}
};

let mut fairness_threshold: Option<U256> = Default::default();
let mut requested_timeout_on_problems = false;

if let Some(value) = parts.get(3) {
match U256::from_dec_str(value) {
match U256::from_str_radix(value, 10) {
Ok(parsed_fairness_threshold) => {
fairness_threshold = Some(parsed_fairness_threshold);
}
Expand Down Expand Up @@ -744,12 +745,12 @@ impl FromStr for CowAmmConfig {
.next()
.context("config is missing factory")?
.parse()
.context("could not parse factory as H160")?;
.context("could not parse factory as Address")?;
let helper = parts
.next()
.context("config is missing helper")?
.parse()
.context("could not parse helper as H160")?;
.context("could not parse helper as Address")?;
let index_start = parts
.next()
.context("config is missing index_start")?
Expand All @@ -770,7 +771,7 @@ impl FromStr for CowAmmConfig {

#[cfg(test)]
mod test {
use {super::*, hex_literal::hex};
use {super::*, alloy::primitives::address};

#[test]
fn test_fee_factor_limits() {
Expand Down Expand Up @@ -807,9 +808,9 @@ mod test {
url: Url::parse("http://localhost:8080").unwrap(),
fairness_threshold: None,
requested_timeout_on_problems: false,
submission_account: Account::Address(H160::from_slice(&hex!(
submission_account: Account::Address(address!(
"C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
))),
)),
};
assert_eq!(driver, expected);
}
Expand Down Expand Up @@ -837,10 +838,10 @@ mod test {
let expected = Solver {
name: "name1".into(),
url: Url::parse("http://localhost:8080").unwrap(),
submission_account: Account::Address(H160::from_slice(&hex!(
submission_account: Account::Address(address!(
"C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
))),
fairness_threshold: Some(U256::exp10(18)),
)),
fairness_threshold: Some(U256::from(10).pow(U256::from(18))),
requested_timeout_on_problems: false,
};
assert_eq!(driver, expected);
Expand All @@ -854,9 +855,9 @@ mod test {
let expected = Solver {
name: "name1".into(),
url: Url::parse("http://localhost:8080").unwrap(),
submission_account: Account::Address(H160::from_slice(&hex!(
submission_account: Account::Address(address!(
"C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
))),
)),
fairness_threshold: None,
requested_timeout_on_problems: true,
};
Expand All @@ -870,10 +871,10 @@ mod test {
let expected = Solver {
name: "name1".into(),
url: Url::parse("http://localhost:8080").unwrap(),
submission_account: Account::Address(H160::from_slice(&hex!(
submission_account: Account::Address(address!(
"C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
))),
fairness_threshold: Some(U256::exp10(18)),
)),
fairness_threshold: Some(U256::from(10).pow(U256::from(18))),
requested_timeout_on_problems: true,
};
assert_eq!(driver, expected);
Expand Down
12 changes: 5 additions & 7 deletions crates/autopilot/src/database/competition.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::domain::competition::Score,
alloy::primitives::Address,
alloy::primitives::{Address, U256},
anyhow::Context,
database::{
auction::AuctionId,
Expand All @@ -10,8 +10,6 @@ use {
},
derive_more::Debug,
model::solver_competition::SolverCompetitionDB,
number::conversions::u256_to_big_decimal,
primitive_types::{H160, U256},
std::collections::{BTreeMap, HashMap, HashSet},
};

Expand All @@ -21,9 +19,9 @@ pub struct Competition {
pub reference_scores: HashMap<Address, Score>,
/// Addresses to which the CIP20 participation rewards will be payed out.
/// Usually the same as the solver addresses.
pub participants: HashSet<H160>,
pub participants: HashSet<Address>,
/// External prices for auction.
pub prices: BTreeMap<H160, U256>,
pub prices: BTreeMap<Address, U256>,
/// Winner receives performance rewards if a settlement is finalized on
/// chain before this block height.
pub block_deadline: u64,
Expand Down Expand Up @@ -67,8 +65,8 @@ impl super::Postgres {
.into_iter()
.map(|(token, price)| AuctionPrice {
auction_id: competition.auction_id,
token: ByteArray(token.0),
price: u256_to_big_decimal(&price),
token: ByteArray(token.0.0),
price: number::conversions::alloy::u256_to_big_decimal(&price),
})
.collect::<Vec<_>>()
.as_slice(),
Expand Down
18 changes: 9 additions & 9 deletions crates/autopilot/src/domain/auction/order.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::domain::{self, eth, fee},
primitive_types::{H160, H256, U256},
alloy::primitives::{Address, B256, U256},
std::fmt::{self, Debug, Display, Formatter},
};

Expand Down Expand Up @@ -38,10 +38,10 @@ impl OrderUid {
}

/// Splits an order UID into its parts.
fn parts(&self) -> (H256, H160, u32) {
fn parts(&self) -> (B256, Address, u32) {
(
H256::from_slice(&self.0[0..32]),
H160::from_slice(&self.0[32..52]),
B256::from_slice(&self.0[0..32]),
Address::from_slice(&self.0[32..52]),
u32::from_le_bytes(self.0[52..].try_into().unwrap()),
)
}
Expand Down Expand Up @@ -73,7 +73,7 @@ pub enum Side {

#[derive(Clone, Debug, PartialEq)]
pub struct Interaction {
pub target: H160,
pub target: Address,
pub value: U256,
pub call_data: Vec<u8>,
}
Expand Down Expand Up @@ -175,17 +175,17 @@ pub enum SigningScheme {

#[derive(Copy, Clone, Debug, PartialEq)]
pub struct EcdsaSignature {
pub r: H256,
pub s: H256,
pub r: B256,
pub s: B256,
pub v: u8,
}

impl EcdsaSignature {
/// r + s + v
pub fn to_bytes(self) -> [u8; 65] {
let mut bytes = [0u8; 65];
bytes[..32].copy_from_slice(self.r.as_bytes());
bytes[32..64].copy_from_slice(self.s.as_bytes());
bytes[..32].copy_from_slice(self.r.as_slice());
bytes[32..64].copy_from_slice(self.s.as_slice());
bytes[64] = self.v;
bytes
}
Expand Down
4 changes: 2 additions & 2 deletions crates/autopilot/src/domain/competition/winner_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ mod tests {
},
alloy::primitives::{U256, address},
ethcontract::H160,
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
ethrpc::alloy::conversions::IntoAlloy,
hex_literal::hex,
number::serialization::HexOrDecimalU256,
serde::Deserialize,
Expand Down Expand Up @@ -1404,7 +1404,7 @@ mod tests {
url::Url::parse("http://localhost").unwrap(),
solver_address.to_string(),
None,
crate::arguments::Account::Address(solver_address.into_legacy()),
crate::arguments::Account::Address(solver_address),
false,
)
.await
Expand Down
3 changes: 1 addition & 2 deletions crates/autopilot/src/domain/fee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use {
app_data::Validator,
chrono::{DateTime, Utc},
derive_more::Into,
primitive_types::H160,
rust_decimal::Decimal,
std::{collections::HashSet, str::FromStr},
};
Expand Down Expand Up @@ -75,7 +74,7 @@ impl From<arguments::UpcomingFeePolicies> for Option<UpcomingProtocolFees> {
}
}

pub type ProtocolFeeExemptAddresses = HashSet<H160>;
pub type ProtocolFeeExemptAddresses = HashSet<Address>;

pub struct ProtocolFees {
fee_policies: Vec<ProtocolFee>,
Expand Down
7 changes: 3 additions & 4 deletions crates/autopilot/src/infra/blockchain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use {
self::contracts::Contracts,
crate::{boundary, domain::eth},
alloy::providers::Provider,
alloy::{primitives::U256, providers::Provider},
chain::Chain,
ethrpc::{
Web3,
alloy::conversions::{IntoAlloy, IntoLegacy},
block_stream::CurrentBlockWatcher,
extensions::DebugNamespace,
},
primitive_types::U256,
thiserror::Error,
url::Url,
};
Expand Down Expand Up @@ -134,7 +133,7 @@ impl Ethereum {
.block(block_hash.into())
.await?
.ok_or(Error::TransactionNotFound)?;
into_domain(transaction, receipt, traces, block.timestamp)
into_domain(transaction, receipt, traces, block.timestamp.into_alloy())
.map_err(Error::IncompleteTransactionData)
}
}
Expand Down Expand Up @@ -166,7 +165,7 @@ fn into_domain(
.ok_or(anyhow::anyhow!("missing effective_gas_price"))?
.into_alloy()
.into(),
timestamp: timestamp.as_u32(),
timestamp: u32::try_from(timestamp)?,
trace_calls: trace_calls.into(),
})
}
Expand Down
15 changes: 5 additions & 10 deletions crates/autopilot/src/infra/persistence/dto/auction.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use {
super::order::Order,
crate::domain::{self, auction::Price, eth},
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
alloy::primitives::{Address, U256},
number::serialization::HexOrDecimalU256,
primitive_types::{H160, U256},
serde::{Deserialize, Serialize},
serde_with::serde_as,
std::collections::BTreeMap,
Expand All @@ -20,12 +19,11 @@ pub fn from_domain(auction: domain::RawAuctionData) -> RawAuctionData {
prices: auction
.prices
.into_iter()
.map(|(key, value)| (key.0.into_legacy(), value.get().0.into_legacy()))
.map(|(key, value)| (key.0, value.get().0))
.collect(),
surplus_capturing_jit_order_owners: auction
.surplus_capturing_jit_order_owners
.into_iter()
.map(IntoLegacy::into_legacy)
.collect(),
}
}
Expand All @@ -37,14 +35,13 @@ pub struct RawAuctionData {
pub block: u64,
pub orders: Vec<Order>,
#[serde_as(as = "BTreeMap<_, HexOrDecimalU256>")]
pub prices: BTreeMap<H160, U256>,
pub prices: BTreeMap<Address, U256>,
#[serde(default)]
pub surplus_capturing_jit_order_owners: Vec<H160>,
pub surplus_capturing_jit_order_owners: Vec<Address>,
}

pub type AuctionId = i64;

#[serde_as]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Auction {
Expand All @@ -69,15 +66,13 @@ impl Auction {
.prices
.into_iter()
.map(|(key, value)| {
Price::try_new(value.into_alloy().into())
.map(|price| (eth::TokenAddress(key.into_alloy()), price))
Price::try_new(value.into()).map(|price| (eth::TokenAddress(key), price))
})
.collect::<Result<_, _>>()?,
surplus_capturing_jit_order_owners: self
.auction
.surplus_capturing_jit_order_owners
.into_iter()
.map(IntoAlloy::into_alloy)
.collect(),
})
}
Expand Down
Loading
Loading