-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
funding: add component parameters for LQT (#5020)
Closes #5013. Diverges slightly from the ADR draft in that it creates a nested proto sub-message specific to the LQT. My rationale here was that this is nicer than prefixing every relevant field with "liquidity_tournament", both in the proto definitions, but also in the Rust code, because that way we can have a default for that entire set of parameters, and then the code can explicitly mark the absence of that set as to be interpreted as this default. Also works nicer for the future, in which we might be using the funding component for other things, each of which can cleanly have its own set of parameters. I also added a little utility type for representing percentages. Not strictly necessary, but I think it's a good move towards type safety. The motivation here was all of the annoyance of dealing with keeping track of what u64s were bps or bps^2 or yadda yadda yadda in other parts of the codebase. I've added some relevant unit tests. ## Checklist before requesting a review - [x] I have added guiding text to explain how a reviewer should test these changes. - [x] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: > adds new parameters that can be voted on, so consensus-breaking. --------- Co-authored-by: Erwan Or <[email protected]>
- Loading branch information
1 parent
881cd26
commit 1b1edc2
Showing
9 changed files
with
378 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// Represents a percentage value. | ||
/// | ||
/// Useful for more robust typesafety, versus just passing around a `u64` which | ||
/// is merely *understood* to only contain values in [0, 100]. | ||
/// | ||
/// Defaults to 0%. | ||
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct Percentage(u64); | ||
|
||
impl Percentage { | ||
/// 0% | ||
pub const fn zero() -> Self { | ||
Self(0) | ||
} | ||
|
||
/// Convert this value into a `u64` in [0, 100]; | ||
pub const fn to_percent(self) -> u64 { | ||
self.0 | ||
} | ||
|
||
/// Given an arbitrary `u64`, produce a percentage, *saturating* at 100. | ||
pub fn from_percent(p: u64) -> Self { | ||
Self(u64::min(p.into(), 100)) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_percentage_operations() { | ||
assert_eq!(Percentage::from_percent(101), Percentage::from_percent(100)); | ||
assert_eq!(Percentage::from_percent(48).to_percent(), 48); | ||
} | ||
} |
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.