Skip to content

Commit

Permalink
Don't count surplus of liquidity JIT orders in autopilot (#2688)
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz authored May 17, 2024
1 parent 4a6f155 commit 74ffcc1
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 192 deletions.
36 changes: 34 additions & 2 deletions crates/autopilot/src/database/competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use {
settlement_scores::Score,
},
derivative::Derivative,
model::solver_competition::SolverCompetitionDB,
model::solver_competition::{SolverCompetitionAPI, SolverCompetitionDB},
number::conversions::u256_to_big_decimal,
primitive_types::{H160, U256},
primitive_types::{H160, H256, U256},
sqlx::{types::JsonValue, PgConnection},
std::collections::{BTreeMap, HashSet},
};

Expand Down Expand Up @@ -119,4 +120,35 @@ impl super::Postgres {

ex.commit().await.context("commit")
}

pub async fn find_competition(
auction_id: AuctionId,
ex: &mut PgConnection,
) -> anyhow::Result<Option<SolverCompetitionAPI>> {
database::solver_competition::load_by_id(ex, auction_id)
.await
.context("solver_competition::load_by_id")?
.map(|row| {
deserialize_solver_competition(
row.json,
row.id,
row.tx_hash.map(|hash| H256(hash.0)),
)
})
.transpose()
}
}

fn deserialize_solver_competition(
json: JsonValue,
auction_id: model::auction::AuctionId,
transaction_hash: Option<H256>,
) -> anyhow::Result<SolverCompetitionAPI> {
let common: SolverCompetitionDB =
serde_json::from_value(json).context("deserialize SolverCompetitionDB")?;
Ok(SolverCompetitionAPI {
auction_id,
transaction_hash,
common,
})
}
Loading

0 comments on commit 74ffcc1

Please sign in to comment.