Skip to content

Commit

Permalink
dex(event): add queue_position_close
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Apr 29, 2024
1 parent d4af1d2 commit f2aee1d
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/core/component/dex/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ pub fn position_open(position: &Position) -> pb::EventPositionOpen {
}

pub fn position_close(action: &PositionClose) -> pb::EventPositionClose {
// TODO: should we have another event triggered by the position manager for when
// the position is actually closed?
pb::EventPositionClose {
position_id: Some(action.position_id.into()),
}
}

pub fn queue_position_close(action: &PositionClose) -> pb::EventQueuePositionClose {
pb::EventQueuePositionClose {
position_id: Some(action.position_id.into()),
}
}

pub fn position_withdraw(
position_id: position::Id,
final_position_state: &Position,
Expand Down
14 changes: 14 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 @@ -1399,6 +1399,20 @@ impl ::prost::Name for EventPositionClose {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EventQueuePositionClose {
/// The ID of the position queued that is closed for closure.
#[prost(message, optional, tag = "1")]
pub position_id: ::core::option::Option<PositionId>,
}
impl ::prost::Name for EventQueuePositionClose {
const NAME: &'static str = "EventQueuePositionClose";
const PACKAGE: &'static str = "penumbra.core.component.dex.v1";
fn full_name() -> ::prost::alloc::string::String {
::prost::alloc::format!("penumbra.core.component.dex.v1.{}", Self::NAME)
}
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EventPositionWithdraw {
/// The ID of the withdrawn position.
#[prost(message, optional, tag = "1")]
Expand Down
96 changes: 96 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 @@ -2209,6 +2209,102 @@ impl<'de> serde::Deserialize<'de> for EventPositionWithdraw {
deserializer.deserialize_struct("penumbra.core.component.dex.v1.EventPositionWithdraw", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for EventQueuePositionClose {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
use serde::ser::SerializeStruct;
let mut len = 0;
if self.position_id.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.component.dex.v1.EventQueuePositionClose", len)?;
if let Some(v) = self.position_id.as_ref() {
struct_ser.serialize_field("positionId", v)?;
}
struct_ser.end()
}
}
impl<'de> serde::Deserialize<'de> for EventQueuePositionClose {
#[allow(deprecated)]
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
const FIELDS: &[&str] = &[
"position_id",
"positionId",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
PositionId,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
where
D: serde::Deserializer<'de>,
{
struct GeneratedVisitor;

impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = GeneratedField;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "expected one of: {:?}", &FIELDS)
}

#[allow(unused_variables)]
fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
where
E: serde::de::Error,
{
match value {
"positionId" | "position_id" => Ok(GeneratedField::PositionId),
_ => Ok(GeneratedField::__SkipField__),
}
}
}
deserializer.deserialize_identifier(GeneratedVisitor)
}
}
struct GeneratedVisitor;
impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
type Value = EventQueuePositionClose;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("struct penumbra.core.component.dex.v1.EventQueuePositionClose")
}

fn visit_map<V>(self, mut map_: V) -> std::result::Result<EventQueuePositionClose, V::Error>
where
V: serde::de::MapAccess<'de>,
{
let mut position_id__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::PositionId => {
if position_id__.is_some() {
return Err(serde::de::Error::duplicate_field("positionId"));
}
position_id__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
}
}
Ok(EventQueuePositionClose {
position_id: position_id__,
})
}
}
deserializer.deserialize_struct("penumbra.core.component.dex.v1.EventQueuePositionClose", FIELDS, GeneratedVisitor)
}
}
impl serde::Serialize for EventSwap {
#[allow(deprecated)]
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
5 changes: 5 additions & 0 deletions proto/penumbra/penumbra/core/component/dex/v1/dex.proto
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ message EventPositionClose {
PositionId position_id = 1;
}

message EventQueuePositionClose {
// The ID of the position queued that is closed for closure.
PositionId position_id = 1;
}

message EventPositionWithdraw {
// The ID of the withdrawn position.
PositionId position_id = 1;
Expand Down

0 comments on commit f2aee1d

Please sign in to comment.