Skip to content

Commit

Permalink
Merge branch 'main' into 2831/improve-auction-update
Browse files Browse the repository at this point in the history
# Conflicts:
#	crates/autopilot/src/infra/persistence/mod.rs
  • Loading branch information
squadgazzz committed Sep 4, 2024
2 parents 72d8b7a + 41334ea commit 55eb516
Show file tree
Hide file tree
Showing 35 changed files with 1,785 additions and 860 deletions.
16 changes: 0 additions & 16 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ pub struct Arguments {
#[clap(long, env, use_value_delimiter = true)]
pub unsupported_tokens: Vec<H160>,

/// The amount of time a classification of a token into good or
/// bad is valid for.
#[clap(
long,
env,
default_value = "10m",
value_parser = humantime::parse_duration,
)]
pub token_quality_cache_expiry: Duration,

/// The number of pairs that are automatically updated in the pool cache.
#[clap(long, env, default_value = "200")]
pub pool_cache_lru_size: NonZeroUsize,
Expand Down Expand Up @@ -254,7 +244,6 @@ impl std::fmt::Display for Arguments {
skip_event_sync,
allowed_tokens,
unsupported_tokens,
token_quality_cache_expiry,
pool_cache_lru_size,
native_price_estimators,
min_order_validity_period,
Expand Down Expand Up @@ -298,11 +287,6 @@ impl std::fmt::Display for Arguments {
writeln!(f, "skip_event_sync: {}", skip_event_sync)?;
writeln!(f, "allowed_tokens: {:?}", allowed_tokens)?;
writeln!(f, "unsupported_tokens: {:?}", unsupported_tokens)?;
writeln!(
f,
"token_quality_cache_expiry: {:?}",
token_quality_cache_expiry
)?;
writeln!(f, "pool_cache_lru_size: {}", pool_cache_lru_size)?;
writeln!(f, "native_price_estimators: {}", native_price_estimators)?;
writeln!(
Expand Down
38 changes: 38 additions & 0 deletions crates/autopilot/src/domain/auction/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,51 @@ pub enum Signature {
PreSign,
}

impl Signature {
pub fn scheme(&self) -> SigningScheme {
match self {
Signature::Eip712(_) => SigningScheme::Eip712,
Signature::EthSign(_) => SigningScheme::EthSign,
Signature::Eip1271(_) => SigningScheme::Eip1271,
Signature::PreSign => SigningScheme::PreSign,
}
}

pub fn to_bytes(&self) -> Vec<u8> {
match self {
Self::Eip712(signature) | Self::EthSign(signature) => signature.to_bytes().to_vec(),
Self::Eip1271(signature) => signature.clone(),
Self::PreSign => Vec::new(),
}
}
}

#[derive(Clone, Debug, PartialEq)]
pub enum SigningScheme {
Eip712,
EthSign,
Eip1271,
PreSign,
}

#[derive(Copy, Clone, Debug, PartialEq)]
pub struct EcdsaSignature {
pub r: H256,
pub s: H256,
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[64] = self.v;
bytes
}
}

/// An amount denominated in the sell token for [`Side::Sell`] [`Order`]s, or in
/// the buy token for [`Side::Buy`] [`Order`]s.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
14 changes: 8 additions & 6 deletions crates/autopilot/src/domain/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ pub use primitive_types::{H160, H256, U256};
pub struct Address(pub H160);

/// Block number.
#[derive(Debug, Copy, Clone, From, PartialEq, PartialOrd)]
#[derive(Debug, Copy, Clone, From, PartialEq, PartialOrd, Default)]
pub struct BlockNo(pub u64);

/// A transaction ID, AKA transaction hash.
#[derive(Debug, Copy, Clone, From)]
#[derive(Debug, Copy, Clone, From, Default)]
pub struct TxId(pub H256);

/// An ERC20 token address.
Expand Down Expand Up @@ -123,7 +123,7 @@ pub struct Gas(pub U256);
/// The `effective_gas_price` as defined by EIP-1559.
///
/// https://eips.ethereum.org/EIPS/eip-1559#specification
#[derive(Debug, Clone, Copy, Display)]
#[derive(Debug, Clone, Copy, Display, Default)]
pub struct EffectiveGasPrice(pub Ether);

impl From<U256> for EffectiveGasPrice {
Expand Down Expand Up @@ -218,7 +218,7 @@ pub struct Asset {
}

/// An amount of native Ether tokens denominated in wei.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, From, Into, Display)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, From, Into, Display, Default)]
pub struct Ether(pub U256);

impl std::ops::Add for Ether {
Expand Down Expand Up @@ -263,7 +263,7 @@ pub struct Event {
}

/// Any type of on-chain transaction.
#[derive(Debug)]
#[derive(Debug, Clone, Default)]
pub struct Transaction {
/// The hash of the transaction.
pub hash: TxId,
Expand All @@ -273,8 +273,10 @@ pub struct Transaction {
pub input: Calldata,
/// The block number of the block that contains the transaction.
pub block: BlockNo,
/// The timestamp of the block that contains the transaction.
pub timestamp: u32,
/// The gas used by the transaction.
pub gas: Gas,
/// The effective gas price of the transaction.
pub effective_gas_price: EffectiveGasPrice,
pub gas_price: EffectiveGasPrice,
}
19 changes: 0 additions & 19 deletions crates/autopilot/src/domain/settlement/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,3 @@ pub struct Auction {
/// surplus if settled.
pub surplus_capturing_jit_order_owners: HashSet<domain::eth::Address>,
}

impl Auction {
/// Protocol defines rules whether an order is eligible to contribute to the
/// surplus of a settlement.
pub fn is_surplus_capturing(&self, order: &domain::OrderUid) -> bool {
// All orders in the auction contribute to surplus
if self.orders.contains_key(order) {
return true;
}
// Some JIT orders contribute to surplus, for example COW AMM orders
if self
.surplus_capturing_jit_order_owners
.contains(&order.owner())
{
return true;
}
false
}
}
Loading

0 comments on commit 55eb516

Please sign in to comment.