Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
Sorts uniswaps according to execution plan. (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Correia authored Mar 11, 2021
1 parent 83368d6 commit 4dcc6cf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions solver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ structopt = { version = "0.3" }
tokio = { version = "0.2", features =["macros", "rt-threaded", "time"] }
tracing = "0.1"
web3 = { version = "0.15", default-features = false, features = ["http-tls"] }
itertools = "0.10"

[dev-dependencies]
tracing-subscriber = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion solver/src/http_solver/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct UpdatedUniswapModel {
pub exec_plan: ExecutionPlanCoordinatesModel,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ExecutionPlanCoordinatesModel {
pub sequence: u32,
pub position: u32,
Expand Down
3 changes: 3 additions & 0 deletions solver/src/http_solver/settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
settlement::Settlement,
};
use anyhow::{anyhow, ensure, Result};
use itertools::Itertools;
use model::order::OrderKind;
use primitive_types::{H160, U256};
use std::{
Expand Down Expand Up @@ -130,6 +131,8 @@ fn match_prepared_and_settled_amms(
settled_orders
.into_iter()
.filter(|(_, settled)| !(settled.balance_update1 == 0 && settled.balance_update2 == 0))
// .sorted_by_key(|su| {&su.1.exec_plan}) // How to make this work?
.sorted_by(|a, b| a.1.exec_plan.cmp(&b.1.exec_plan))
.map(|(index, settled)| {
let prepared = prepared_orders
.remove(index.as_str())
Expand Down

0 comments on commit 4dcc6cf

Please sign in to comment.