Skip to content

Commit

Permalink
Filter orders with buy token == sell token (#1421)
Browse files Browse the repository at this point in the history
In the pricegraph high level operations we already check that the two tokens in the market are different. I think the same makes sense for the orders in the orderbook as buying and selling the same token does not make sense.

Edit: This is already enforced in the smart contract so it probably makes more sense to enforce this when parsing the Element but we 'd have to add another possible error type to that function.

### Test Plan
Existing tests still pass and new test.
  • Loading branch information
e00E authored Sep 11, 2020
1 parent be798b3 commit bf399bd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pricegraph/src/orderbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl Orderbook {
for (order, element) in elements
.into_iter()
.filter(|element| !is_dust_order(element))
.filter(|element| element.pair.buy != element.pair.sell)
.filter_map(|element| Order::new(&element).map(move |order| (order, element)))
{
let TokenPair { buy, sell } = element.pair;
Expand Down Expand Up @@ -614,6 +615,22 @@ mod tests {
assert_eq!(orderbook.num_orders(), 0);
}

#[test]
fn ignores_orders_with_invalid_market() {
let orderbook = orderbook! {
users {
@1 {
token 0 => 1_000_000_000,
}
}
orders {
owner @1 buying 0 [1_000_000_000] selling 0 [1_000_000_000],
}
};

assert_eq!(orderbook.num_orders(), 0);
}

#[test]
fn fills_path_and_updates_projection() {
// /---1.0---v
Expand Down

0 comments on commit bf399bd

Please sign in to comment.