-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for no liquidity limit order placement (#2854)
# Description We currently require all orders to have quote in order to accurately compute fee policies (price improvement policies requires quote data). In the absence of the quote we don't allow order placement and exclude the order from solvable orders (inconsistently on a one-off code path outside of the solvable orders cache where it doesn't get flagged as "filtered" or "invalid" thus being silently ignored). This seems unnecessarily restrictive. In the absence of a quote we could simply assume that the limit price itself was the quote (ie apply a pure surplus fee policy) to the order. This would allow placing limit orders for tokens which are not yet tradables but will become tradable soon. @sunce86 am I missing any other reason why we need a quote? # Changes - [x] Allow order placement if a quote wasn't found due to a pricing error - [x] Don't filter out orders from the auction for which we don't have a quote - [x] Assume the limit amounts are equal to the quote amounts for fee policy application in case we cannot find a quote ## How to test Introduced an e2e test showing that this works
- Loading branch information
Showing
9 changed files
with
270 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
pub struct ProtocolFeesConfig(pub Vec<ProtocolFee>); | ||
|
||
#[derive(Clone)] | ||
pub struct ProtocolFee { | ||
pub policy: FeePolicyKind, | ||
pub policy_order_class: FeePolicyOrderClass, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub enum FeePolicyOrderClass { | ||
Market, | ||
Limit, | ||
Any, | ||
} | ||
|
||
impl std::fmt::Display for FeePolicyOrderClass { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
FeePolicyOrderClass::Market => write!(f, "market"), | ||
FeePolicyOrderClass::Limit => write!(f, "limit"), | ||
FeePolicyOrderClass::Any => write!(f, "any"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub enum FeePolicyKind { | ||
/// How much of the order's surplus should be taken as a protocol fee. | ||
Surplus { factor: f64, max_volume_factor: f64 }, | ||
/// How much of the order's volume should be taken as a protocol fee. | ||
Volume { factor: f64 }, | ||
/// How much of the order's price improvement should be taken as a protocol | ||
/// fee where price improvement is a difference between the executed price | ||
/// and the best quote. | ||
PriceImprovement { factor: f64, max_volume_factor: f64 }, | ||
} | ||
|
||
impl std::fmt::Display for ProtocolFee { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let order_class_str = &self.policy_order_class.to_string(); | ||
match &self.policy { | ||
FeePolicyKind::Surplus { | ||
factor, | ||
max_volume_factor, | ||
} => write!( | ||
f, | ||
"surplus:{}:{}:{}", | ||
factor, max_volume_factor, order_class_str | ||
), | ||
FeePolicyKind::Volume { factor } => { | ||
write!(f, "volume:{}:{}", factor, order_class_str) | ||
} | ||
FeePolicyKind::PriceImprovement { | ||
factor, | ||
max_volume_factor, | ||
} => write!( | ||
f, | ||
"priceImprovement:{}:{}:{}", | ||
factor, max_volume_factor, order_class_str | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for ProtocolFeesConfig { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let fees_str = self | ||
.0 | ||
.iter() | ||
.map(|fee| fee.to_string()) | ||
.collect::<Vec<_>>() | ||
.join(","); | ||
write!(f, "--fee-policies={}", fees_str) | ||
} | ||
} |
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
Oops, something went wrong.