-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
competition::Solution
to domain (#2725)
# Description A preparation PR for task #2718 Moves `Solution` to `domain` and refactors the rest of the code to reuse this object. ## How to test existing tests
- Loading branch information
Showing
4 changed files
with
138 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use { | ||
super::{auction, eth}, | ||
crate::domain, | ||
number::nonzero::U256 as NonZeroU256, | ||
std::collections::HashMap, | ||
}; | ||
|
||
type SolutionId = u64; | ||
|
||
pub struct Solution { | ||
id: SolutionId, | ||
account: eth::Address, | ||
score: NonZeroU256, | ||
orders: HashMap<domain::OrderUid, TradedAmounts>, | ||
// uniform prices for all tokens | ||
prices: HashMap<eth::TokenAddress, auction::Price>, | ||
} | ||
|
||
impl Solution { | ||
pub fn new( | ||
id: SolutionId, | ||
account: eth::Address, | ||
score: NonZeroU256, | ||
orders: HashMap<domain::OrderUid, TradedAmounts>, | ||
prices: HashMap<eth::TokenAddress, auction::Price>, | ||
) -> Self { | ||
Self { | ||
id, | ||
account, | ||
score, | ||
orders, | ||
prices, | ||
} | ||
} | ||
|
||
pub fn id(&self) -> SolutionId { | ||
self.id | ||
} | ||
|
||
pub fn account(&self) -> eth::Address { | ||
self.account | ||
} | ||
|
||
pub fn score(&self) -> NonZeroU256 { | ||
self.score | ||
} | ||
|
||
pub fn order_ids(&self) -> impl Iterator<Item = &domain::OrderUid> { | ||
self.orders.keys() | ||
} | ||
|
||
pub fn orders(&self) -> &HashMap<domain::OrderUid, TradedAmounts> { | ||
&self.orders | ||
} | ||
|
||
pub fn prices(&self) -> &HashMap<eth::TokenAddress, auction::Price> { | ||
&self.prices | ||
} | ||
} | ||
|
||
pub struct TradedAmounts { | ||
/// The effective amount that left the user's wallet including all fees. | ||
pub sell: eth::TokenAmount, | ||
/// The effective amount the user received after all fees. | ||
pub buy: eth::TokenAmount, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod auction; | ||
pub mod competition; | ||
pub mod eth; | ||
pub mod fee; | ||
pub mod quote; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters