-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5cdd49
commit a7e0f61
Showing
7 changed files
with
91 additions
and
43 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
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
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
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,41 @@ | ||
use crate::error::DriftResult; | ||
use crate::math::auction::calculate_auction_price; | ||
use crate::math::casting::Cast; | ||
use crate::math::safe_math::SafeMath; | ||
use crate::state::user::Order; | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq)] | ||
pub enum FillMode { | ||
Fill, | ||
PlaceAndMake, | ||
PlaceAndTake, | ||
} | ||
|
||
impl FillMode { | ||
pub fn get_limit_price( | ||
&self, | ||
order: &Order, | ||
valid_oracle_price: Option<i64>, | ||
slot: u64, | ||
tick_size: u64, | ||
) -> DriftResult<Option<u64>> { | ||
match self { | ||
FillMode::Fill | FillMode::PlaceAndMake => { | ||
order.get_limit_price(valid_oracle_price, None, slot, tick_size) | ||
} | ||
FillMode::PlaceAndTake => { | ||
if order.has_auction() { | ||
calculate_auction_price( | ||
order, | ||
slot.safe_add(order.auction_duration.cast()?)?, | ||
tick_size, | ||
valid_oracle_price, | ||
) | ||
.map(Some) | ||
} else { | ||
order.get_limit_price(valid_oracle_price, None, slot, tick_size) | ||
} | ||
} | ||
} | ||
} | ||
} |
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