Skip to content

Commit

Permalink
Remove domain separator
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lord-renkse committed Apr 4, 2024
1 parent c783744 commit 4abdf2a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 44 deletions.
16 changes: 8 additions & 8 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ pub struct Arguments {
#[clap(long, env, default_value = "0.01")]
pub fee_policy_max_partner_fee: FeeFactor,

/// List of addresses which are exempt from the protocol
/// fees
#[clap(long, env, use_value_delimiter = true)]
pub protocol_fee_exempt_addresses: Vec<H160>,

/// Arguments for uploading information to S3.
#[clap(flatten)]
pub s3: infra::persistence::cli::S3,
Expand All @@ -220,11 +225,6 @@ pub struct Arguments {
/// `order_events` database table.
#[clap(long, env, default_value = "30d", value_parser = humantime::parse_duration)]
pub order_events_cleanup_threshold: Duration,

/// List of addresses which receives a specific discount for the protocol
/// fees
#[clap(long, env, use_value_delimiter = true)]
pub protocol_fee_discounted_addresses: Vec<H160>,
}

impl std::fmt::Display for Arguments {
Expand Down Expand Up @@ -267,7 +267,7 @@ impl std::fmt::Display for Arguments {
auction_update_interval,
max_settlement_transaction_wait,
s3,
protocol_fee_discounted_addresses,
protocol_fee_exempt_addresses,
} = self;

write!(f, "{}", shared)?;
Expand Down Expand Up @@ -322,8 +322,8 @@ impl std::fmt::Display for Arguments {
writeln!(f, "fee_policies: {:?}", fee_policies)?;
writeln!(
f,
"protocol_fee_discounted_addresses: {:?}",
protocol_fee_discounted_addresses
"protocol_fee_exempt_addresses: {:?}",
protocol_fee_exempt_addresses
)?;
writeln!(
f,
Expand Down
37 changes: 12 additions & 25 deletions crates/autopilot/src/domain/fee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use {
app_data::Validator,
derive_more::Into,
itertools::Itertools,
model::DomainSeparator,
primitive_types::{H160, U256},
prometheus::core::Number,
std::{collections::HashSet, str::FromStr},
Expand Down Expand Up @@ -52,29 +51,29 @@ impl From<arguments::FeePolicy> for ProtocolFee {
}
}

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

pub struct ProtocolFees {
fee_policies: Vec<ProtocolFee>,
max_partner_fee: FeeFactor,
/// List of addresses which receives a specific discount for the protocol
/// List of addresses which are exempt from the protocol
/// fees
protocol_fee_discounted_addresses: ProtocolFeeDiscountedAddresses,
protocol_fee_exempt_addresses: ProtocolFeeExemptAddresses,
}

impl ProtocolFees {
pub fn new(
fee_policies: &[arguments::FeePolicy],
fee_policy_max_partner_fee: FeeFactor,
protocol_fee_discounted_addresses: &[H160],
protocol_fee_exempt_addresses: &[H160],
) -> Self {
Self {
fee_policies: fee_policies
.iter()
.cloned()
.map(ProtocolFee::from)
.collect(),
protocol_fee_discounted_addresses: protocol_fee_discounted_addresses
protocol_fee_exempt_addresses: protocol_fee_exempt_addresses
.iter()
.cloned()
.collect::<HashSet<_>>(),
Expand All @@ -84,12 +83,7 @@ impl ProtocolFees {

/// Converts an order from the boundary layer to the domain layer, applying
/// protocol fees if necessary.
pub fn apply(
&self,
order: boundary::Order,
quote: &domain::Quote,
domain_separator: &DomainSeparator,
) -> domain::Order {
pub fn apply(&self, order: boundary::Order, quote: &domain::Quote) -> domain::Order {
// If the partner fee is specified, it overwrites the current volume fee policy
if let Some(validated_app_data) = order
.metadata
Expand Down Expand Up @@ -122,19 +116,13 @@ impl ProtocolFees {
buy: quote.buy_amount,
fee: quote.fee,
};
let protocol_fees = match order
.signature
.recover(domain_separator, &order.data.hash_struct())
let protocol_fees = if self
.protocol_fee_exempt_addresses
.contains(&order.metadata.owner)
{
Ok(Some(address))
if self
.protocol_fee_discounted_addresses
.contains(&address.signer) =>
{
vec![]
}
_ => {
self
vec![]
} else {
self
.fee_policies
.iter()
// TODO: support multiple fee policies
Expand All @@ -154,7 +142,6 @@ impl ProtocolFees {
})
.into_iter()
.collect_vec()
}
};
boundary::order::to_domain(order, protocol_fees)
}
Expand Down
7 changes: 2 additions & 5 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,6 @@ pub async fn run(args: Arguments) {
},
));

let domain_separator = DomainSeparator::new(chain_id, eth.contracts().settlement().address());

if let Some(ethflow_contract) = args.ethflow_contract {
let start_block = determine_ethflow_indexing_start(
&skip_event_sync_start,
Expand Down Expand Up @@ -514,7 +512,7 @@ pub async fn run(args: Arguments) {
web3.clone(),
quoter.clone(),
Box::new(custom_ethflow_order_parser),
domain_separator,
DomainSeparator::new(chain_id, eth.contracts().settlement().address()),
eth.contracts().settlement().address(),
);
let broadcaster_event_updater = Arc::new(
Expand Down Expand Up @@ -563,9 +561,8 @@ pub async fn run(args: Arguments) {
domain::ProtocolFees::new(
&args.fee_policies,
args.fee_policy_max_partner_fee,
args.protocol_fee_discounted_addresses.as_slice(),
args.protocol_fee_exempt_addresses.as_slice(),
),
domain_separator,
);

let liveness = Arc::new(Liveness::new(args.max_auction_age));
Expand Down
6 changes: 1 addition & 5 deletions crates/autopilot/src/solvable_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use {
order::{Order, OrderClass, OrderUid},
signature::Signature,
time::now_in_epoch_seconds,
DomainSeparator,
},
number::conversions::u256_to_big_decimal,
primitive_types::{H160, H256, U256},
Expand Down Expand Up @@ -82,7 +81,6 @@ pub struct SolvableOrdersCache {
weth: H160,
limit_order_price_factor: BigDecimal,
protocol_fees: domain::ProtocolFees,
domain_separator: DomainSeparator,
}

type Balances = HashMap<Query, U256>;
Expand All @@ -107,7 +105,6 @@ impl SolvableOrdersCache {
weth: H160,
limit_order_price_factor: BigDecimal,
protocol_fees: domain::ProtocolFees,
domain_separator: DomainSeparator,
) -> Arc<Self> {
let self_ = Arc::new(Self {
min_order_validity_period,
Expand All @@ -125,7 +122,6 @@ impl SolvableOrdersCache {
weth,
limit_order_price_factor,
protocol_fees,
domain_separator,
});
tokio::task::spawn(
update_task(Arc::downgrade(&self_), update_interval, current_block)
Expand Down Expand Up @@ -246,7 +242,7 @@ impl SolvableOrdersCache {
.into_iter()
.filter_map(|order| {
if let Some(quote) = db_solvable_orders.quotes.get(&order.metadata.uid.into()) {
Some(self.protocol_fees.apply(order, quote, &self.domain_separator))
Some(self.protocol_fees.apply(order, quote))
} else {
tracing::warn!(order_uid = %order.metadata.uid, "order is skipped, quote is missing");
None
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/protocol_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ async fn execute_test(web3: Web3, autopilot_config: Vec<impl ToString>, test_cas
];
if test_case.protocol_fee_whitelisted_trader_address {
config.push(format!(
"--protocol-fee-discounted-addresses={:?}",
"--protocol-fee-exempt-addresses={:?}",
trader.address()
));
}
Expand Down

0 comments on commit 4abdf2a

Please sign in to comment.