Skip to content

Commit e519dff

Browse files
committed
Optional timestamp
1 parent c44359e commit e519dff

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

crates/orderbook/src/arguments.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ pub struct VolumeFeeConfig {
154154
/// This is a decimal value (e.g., 0.0002 for 0.02% or 2 basis points).
155155
/// The fee is applied to the surplus token (buy token for sell orders,
156156
/// sell token for buy orders).
157-
#[clap(long, env)]
157+
#[clap(long = "volume_fee_factor", env = "VOLUME_FEE_FACTOR")]
158158
pub factor: FeeFactor,
159159

160160
/// The timestamp from which the volume fee becomes effective.
161-
#[clap(long, env)]
162-
pub effective_from_timestamp: DateTime<Utc>,
161+
#[clap(
162+
long = "volume_fee_effective_timestamp",
163+
env = "VOLUME_FEE_EFFECTIVE_TIMESTAMP"
164+
)]
165+
pub effective_from_timestamp: Option<DateTime<Utc>>,
163166
}
164167

165168
#[derive(Debug, Clone, Copy, PartialEq, Into)]

crates/orderbook/src/quoter.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn get_adjusted_quote_data(
165165
) -> anyhow::Result<AdjustedQuoteData> {
166166
let Some(factor) = volume_fee
167167
// Only apply volume fee if effective timestamp is in the past
168-
.filter(|config| config.effective_from_timestamp <= Utc::now())
168+
.filter(|config| config.effective_from_timestamp.is_none_or(|ts| ts <= Utc::now()))
169169
.map(|config| config.factor)
170170
else {
171171
return Ok(AdjustedQuoteData {
@@ -276,7 +276,7 @@ mod tests {
276276
let volume_fee = FeeFactor::try_from(0.0002).unwrap(); // 0.02% = 2 bps
277277
let volume_fee_config = VolumeFeeConfig {
278278
factor: volume_fee,
279-
effective_from_timestamp: Utc::now(),
279+
effective_from_timestamp: None,
280280
};
281281

282282
// Selling 100 tokens, expecting to buy 100 tokens
@@ -307,7 +307,7 @@ mod tests {
307307
let volume_fee = FeeFactor::try_from(0.0002).unwrap(); // 0.02% = 2 bps
308308
let volume_fee_config = VolumeFeeConfig {
309309
factor: volume_fee,
310-
effective_from_timestamp: Utc::now(),
310+
effective_from_timestamp: None,
311311
};
312312

313313
// Buying 100 tokens, expecting to sell 100 tokens, with no network fee
@@ -336,7 +336,7 @@ mod tests {
336336
let volume_fee = FeeFactor::try_from(0.0002).unwrap(); // 0.02% = 2 bps
337337
let volume_fee_config = VolumeFeeConfig {
338338
factor: volume_fee,
339-
effective_from_timestamp: Utc::now(),
339+
effective_from_timestamp: None,
340340
};
341341

342342
// Buying 100 tokens, expecting to sell 100 tokens, with 5 token network fee
@@ -370,7 +370,7 @@ mod tests {
370370
let volume_fee = FeeFactor::try_from(0.001).unwrap(); // 0.1% = 10 bps
371371
let volume_fee_config = VolumeFeeConfig {
372372
factor: volume_fee,
373-
effective_from_timestamp: Utc::now(),
373+
effective_from_timestamp: None,
374374
};
375375

376376
// Selling 100 tokens, expecting to buy 200 tokens (2:1 price ratio)
@@ -405,7 +405,7 @@ mod tests {
405405
let volume_fee = FeeFactor::try_from(factor).unwrap();
406406
let volume_fee_config = VolumeFeeConfig {
407407
factor: volume_fee,
408-
effective_from_timestamp: Utc::now(),
408+
effective_from_timestamp: None,
409409
};
410410

411411
let quote = create_test_quote(to_wei(100), to_wei(100));
@@ -420,4 +420,29 @@ mod tests {
420420
assert_eq!(result.protocol_fee_bps, Some(expected_bps.to_string()));
421421
}
422422
}
423+
424+
#[test]
425+
fn test_ignore_volume_fees_before_effective_date() {
426+
let volume_fee = FeeFactor::try_from(0.001).unwrap(); // 0.1% = 10 bps
427+
let future_timestamp = Utc::now() + chrono::Duration::days(1);
428+
let volume_fee_config = VolumeFeeConfig {
429+
factor: volume_fee,
430+
effective_from_timestamp: Some(future_timestamp),
431+
};
432+
433+
// Selling 100 tokens, expecting to buy 100 tokens
434+
let quote = create_test_quote(to_wei(100), to_wei(100));
435+
let side = OrderQuoteSide::Sell {
436+
sell_amount: model::quote::SellAmount::BeforeFee {
437+
value: number::nonzero::U256::try_from(to_wei(100)).unwrap(),
438+
},
439+
};
440+
441+
let result = get_adjusted_quote_data(&quote, Some(&volume_fee_config), &side).unwrap();
442+
443+
// Since the effective date is in the future, no volume fee should be applied
444+
assert_eq!(result.sell_amount, to_wei(100));
445+
assert_eq!(result.buy_amount, to_wei(100));
446+
assert_eq!(result.protocol_fee_bps, None);
447+
}
423448
}

0 commit comments

Comments
 (0)