Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dex: add max_positions_per_pair to parameters #4158

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
4 changes: 3 additions & 1 deletion crates/core/app/src/params/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ impl AppParameters {
new.check_valid()?;
// TODO: move the checks below into their respective components.
// Tracked by #3593

let AppParameters {
chain_id,
community_pool_params:
Expand Down Expand Up @@ -75,6 +74,7 @@ impl AppParameters {
is_enabled: _,
fixed_candidates: _,
max_hops: _,
max_positions_per_pair: _,
},
// IMPORTANT: Don't use `..` here! We want to ensure every single field is verified!
} = self;
Expand Down Expand Up @@ -169,6 +169,7 @@ impl AppParameters {
is_enabled: _,
fixed_candidates: _,
max_hops: _,
max_positions_per_pair: _,
},
// IMPORTANT: Don't use `..` here! We want to ensure every single field is verified!
} = self;
Expand Down Expand Up @@ -244,6 +245,7 @@ impl AppParameters {
*min_validator_stake >= 1_000_000u128.into(),
"the minimum validator stake must be at least 1penumbra",
),
// TODO(erwan): add a `max_positions_per_pair` check
])
}

Expand Down
5 changes: 5 additions & 0 deletions crates/core/component/dex/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct DexParameters {
pub is_enabled: bool,
pub fixed_candidates: Vec<asset::Id>,
pub max_hops: u32,
pub max_positions_per_pair: u32,
}

impl DomainType for DexParameters {
Expand All @@ -28,6 +29,7 @@ impl TryFrom<pb::DexParameters> for DexParameters {
.map(|id| id.try_into())
.collect::<Result<_, _>>()?,
max_hops: msg.max_hops,
max_positions_per_pair: msg.max_positions_per_pair,
})
}
}
Expand All @@ -42,6 +44,7 @@ impl From<DexParameters> for pb::DexParameters {
.map(Into::into)
.collect(),
max_hops: params.max_hops,
max_positions_per_pair: params.max_positions_per_pair,
}
}
}
Expand All @@ -63,6 +66,8 @@ impl Default for DexParameters {
cache.get_unit("test_btc").unwrap().id(),
],
max_hops: 4,
// TODO(erwan): setting this to 10 for testing.
max_positions_per_pair: 10,
}
}
}
5 changes: 5 additions & 0 deletions crates/proto/src/gen/penumbra.core.component.dex.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,11 @@ pub struct DexParameters {
/// The number of hops to traverse while routing from A to B.
#[prost(uint32, tag = "3")]
pub max_hops: u32,
/// The maximum number of positions per trading pair.
/// If this number is exceeded, positions with the least
/// inventory get evicted from the DEX.
#[prost(uint32, tag = "4")]
pub max_positions_per_pair: u32,
}
impl ::prost::Name for DexParameters {
const NAME: &'static str = "DexParameters";
Expand Down
20 changes: 20 additions & 0 deletions crates/proto/src/gen/penumbra.core.component.dex.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,9 @@ impl serde::Serialize for DexParameters {
if self.max_hops != 0 {
len += 1;
}
if self.max_positions_per_pair != 0 {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.component.dex.v1.DexParameters", len)?;
if self.is_enabled {
struct_ser.serialize_field("isEnabled", &self.is_enabled)?;
Expand All @@ -1062,6 +1065,9 @@ impl serde::Serialize for DexParameters {
if self.max_hops != 0 {
struct_ser.serialize_field("maxHops", &self.max_hops)?;
}
if self.max_positions_per_pair != 0 {
struct_ser.serialize_field("maxPositionsPerPair", &self.max_positions_per_pair)?;
}
struct_ser.end()
}
}
Expand All @@ -1078,13 +1084,16 @@ impl<'de> serde::Deserialize<'de> for DexParameters {
"fixedCandidates",
"max_hops",
"maxHops",
"max_positions_per_pair",
"maxPositionsPerPair",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
IsEnabled,
FixedCandidates,
MaxHops,
MaxPositionsPerPair,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand All @@ -1110,6 +1119,7 @@ impl<'de> serde::Deserialize<'de> for DexParameters {
"isEnabled" | "is_enabled" => Ok(GeneratedField::IsEnabled),
"fixedCandidates" | "fixed_candidates" => Ok(GeneratedField::FixedCandidates),
"maxHops" | "max_hops" => Ok(GeneratedField::MaxHops),
"maxPositionsPerPair" | "max_positions_per_pair" => Ok(GeneratedField::MaxPositionsPerPair),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand All @@ -1132,6 +1142,7 @@ impl<'de> serde::Deserialize<'de> for DexParameters {
let mut is_enabled__ = None;
let mut fixed_candidates__ = None;
let mut max_hops__ = None;
let mut max_positions_per_pair__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::IsEnabled => {
Expand All @@ -1154,6 +1165,14 @@ impl<'de> serde::Deserialize<'de> for DexParameters {
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::MaxPositionsPerPair => {
if max_positions_per_pair__.is_some() {
return Err(serde::de::Error::duplicate_field("maxPositionsPerPair"));
}
max_positions_per_pair__ =
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -1163,6 +1182,7 @@ impl<'de> serde::Deserialize<'de> for DexParameters {
is_enabled: is_enabled__.unwrap_or_default(),
fixed_candidates: fixed_candidates__.unwrap_or_default(),
max_hops: max_hops__.unwrap_or_default(),
max_positions_per_pair: max_positions_per_pair__.unwrap_or_default(),
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
4 changes: 4 additions & 0 deletions proto/penumbra/penumbra/core/component/dex/v1/dex.proto
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ message DexParameters {
repeated asset.v1.AssetId fixed_candidates = 2;
// The number of hops to traverse while routing from A to B.
uint32 max_hops = 3;
// The maximum number of positions per trading pair.
// If this number is exceeded, positions with the least
// inventory get evicted from the DEX.
uint32 max_positions_per_pair = 4;
}

message GenesisContent {
Expand Down
Loading