Skip to content

Commit f506dc6

Browse files
authored
ETH-flow refunder: allow negative slippage orders (#3334)
# Description A few similar eth-flow orders were not automatically refunded([example](https://explorer.cow.fi/arb1/orders/0x36a494c38ad0bab7c6f73187ba39df9293d4b9342fe7fa2830d56bf54436de8c552fcecc218158fff20e505c8f3ad24f8e1dd33cffffffff)) since the price specified in the order was a bit better than the quote's, as a result, the computed slippage was negative. The config currently supports the positive values only. This PR address this by allowing specifying the negative price deviations. This PR needs to be merged together with a corresponding infra PR since the config param was renamed. ## How to test Observe logs.
1 parent a92e23b commit f506dc6

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

crates/database/src/ethflow_orders.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub async fn refundable_orders(
114114
ex: &mut PgConnection,
115115
since_valid_to: i64,
116116
min_validity_duration: i64,
117-
min_slippage: f64,
117+
min_price_deviation: f64,
118118
) -> Result<Vec<EthOrderPlacement>, sqlx::Error> {
119119
// condition (1.0 - o.buy_amount / GREATEST(oq.buy_amount,1)) >= $3 is added to
120120
// skip refunding orders that have unrealistic slippage set. Those orders are
@@ -145,7 +145,7 @@ AND eo.valid_to - extract(epoch from creation_timestamp)::int > $2
145145
sqlx::query_as(QUERY)
146146
.bind(since_valid_to)
147147
.bind(min_validity_duration)
148-
.bind(min_slippage)
148+
.bind(min_price_deviation)
149149
.fetch_all(ex)
150150
.await
151151
}

crates/e2e/tests/e2e/refunder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ async fn refunder_tx(web3: Web3) {
126126
web3,
127127
vec![ethflow_contract.clone(), ethflow_contract_2.clone()],
128128
validity_duration as i64 / 2,
129-
10u64,
129+
10i64,
130130
refunder.account().clone(),
131131
);
132132

crates/refunder/src/arguments.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ pub struct Arguments {
3030
)]
3131
pub min_validity_duration: Duration,
3232

33-
/// Minimum slippage an order must have, in order
34-
/// to be eligble for refunding
35-
/// Front-end will place orders with a default slippage of 2%
36-
/// hence, we are requiring as a default 190 bps or 1.9 %
33+
/// Minimum *required* price deviation from quote (in basis points),
34+
/// for an order to be eligible for refunding.
35+
/// Negative values mean the order was placed with a better-than-quote price
36+
/// (less executable). For example:
37+
/// - A value of `-10` allows refunding orders up to 0.10% better than
38+
/// quote(price improvement)
39+
/// - A value of `0` requires the order to be at least equal to quote
40+
/// - A value of `190` (default) allows refunding only orders with ≥1.9%
41+
/// slippage
3742
#[clap(long, env, default_value = "190")]
38-
pub min_slippage_bps: u64,
43+
pub min_price_deviation_bps: i64,
3944

4045
/// Url of the Postgres database. By default connects to locally running
4146
/// postgres.
@@ -70,7 +75,7 @@ impl std::fmt::Display for Arguments {
7075
http_client,
7176
ethrpc,
7277
min_validity_duration,
73-
min_slippage_bps,
78+
min_price_deviation_bps,
7479
node_url,
7580
chain_id,
7681
ethflow_contracts,
@@ -84,7 +89,7 @@ impl std::fmt::Display for Arguments {
8489
write!(f, "{}", ethrpc)?;
8590
write!(f, "{}", logging)?;
8691
writeln!(f, "min_validity_duration: {:?}", min_validity_duration)?;
87-
writeln!(f, "min_slippage_bps: {}", min_slippage_bps)?;
92+
writeln!(f, "min_price_deviation_bps: {}", min_price_deviation_bps)?;
8893
let _intentionally_ignored = db_url;
8994
writeln!(f, "db_url: SECRET")?;
9095
writeln!(f, "node_url: {}", node_url)?;

crates/refunder/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub async fn run(args: arguments::Arguments) {
6868
web3,
6969
ethflow_contracts,
7070
i64::try_from(args.min_validity_duration.as_secs()).unwrap_or(i64::MAX),
71-
args.min_slippage_bps,
71+
args.min_price_deviation_bps,
7272
refunder_account,
7373
);
7474
loop {

crates/refunder/src/refund_service.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct RefundService {
2626
pub web3: Web3,
2727
pub ethflow_contracts: Vec<CoWSwapEthFlow>,
2828
pub min_validity_duration: i64,
29-
pub min_slippage: f64,
29+
pub min_price_deviation: f64,
3030
pub submitter: Submitter,
3131
}
3232

@@ -43,15 +43,15 @@ impl RefundService {
4343
web3: Web3,
4444
ethflow_contracts: Vec<CoWSwapEthFlow>,
4545
min_validity_duration: i64,
46-
min_slippage_bps: u64,
46+
min_price_deviation_bps: i64,
4747
account: Account,
4848
) -> Self {
4949
RefundService {
5050
db,
5151
web3: web3.clone(),
5252
ethflow_contracts,
5353
min_validity_duration,
54-
min_slippage: min_slippage_bps as f64 / 10000f64,
54+
min_price_deviation: min_price_deviation_bps as f64 / 10000f64,
5555
submitter: Submitter {
5656
web3: web3.clone(),
5757
account,
@@ -81,7 +81,7 @@ impl RefundService {
8181
&mut ex,
8282
block_time,
8383
self.min_validity_duration,
84-
self.min_slippage,
84+
self.min_price_deviation,
8585
)
8686
.await
8787
.map_err(|err| {

0 commit comments

Comments
 (0)