From 5793168e2cc9d8f9723e021ca13b1bf14cfdaa89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=BAc=C3=A1s=20Meier?= Date: Thu, 13 Jun 2024 14:45:45 -0800 Subject: [PATCH] Add an event for auction withdrawals (#4612) This will make it easy to fill in withdrawal views later, since we'll have an event with the exact state of the auction at that time. ## Describe your changes This adds a new proto event for when an auction is withdrawn, including the state of the auction at that time. ## Issue ticket number and link This can be seen as laying the groundwork for #4219 once we're able to link events in the view services we implement. ## Checklist before requesting a review - [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: > This just adds a new event, without changing existing protos. --- .../auction/src/component/dutch_auction.rs | 4 + crates/core/component/auction/src/event.rs | 11 ++ .../gen/penumbra.core.component.auction.v1.rs | 15 +++ ...enumbra.core.component.auction.v1.serde.rs | 113 ++++++++++++++++++ .../proto/src/gen/proto_descriptor.bin.no_lfs | Bin 535853 -> 536184 bytes .../core/component/auction/v1/auction.proto | 5 + 6 files changed, 148 insertions(+) diff --git a/crates/core/component/auction/src/component/dutch_auction.rs b/crates/core/component/auction/src/component/dutch_auction.rs index 3a39ab12c7..e93cc772c1 100644 --- a/crates/core/component/auction/src/component/dutch_auction.rs +++ b/crates/core/component/auction/src/component/dutch_auction.rs @@ -410,6 +410,10 @@ pub(crate) trait DutchAuctionManager: StateWrite { auction.state.next_trigger = None; auction.state.input_reserves = Amount::zero(); auction.state.output_reserves = Amount::zero(); + self.record_proto(event::dutch_auction_withdrawn( + auction.description.id(), + auction.state.clone(), + )); self.write_dutch_auction_state(auction); Ok(withdraw_balance) diff --git a/crates/core/component/auction/src/event.rs b/crates/core/component/auction/src/event.rs index f170bd0909..5463856c47 100644 --- a/crates/core/component/auction/src/event.rs +++ b/crates/core/component/auction/src/event.rs @@ -62,6 +62,17 @@ pub fn dutch_auction_exhausted( } } +/// Event for a Dutch auction that is withdrawn by a user after ending. +pub fn dutch_auction_withdrawn( + id: AuctionId, + state: DutchAuctionState, +) -> pb::EventDutchAuctionWithdrawn { + pb::EventDutchAuctionWithdrawn { + auction_id: Some(id.into()), + state: Some(state.into()), + } +} + // Event for value flowing *into* the auction component. pub fn auction_vcb_credit( asset_id: asset::Id, diff --git a/crates/proto/src/gen/penumbra.core.component.auction.v1.rs b/crates/proto/src/gen/penumbra.core.component.auction.v1.rs index 5c17e61b21..e490a73599 100644 --- a/crates/proto/src/gen/penumbra.core.component.auction.v1.rs +++ b/crates/proto/src/gen/penumbra.core.component.auction.v1.rs @@ -435,6 +435,21 @@ impl ::prost::Name for EventDutchAuctionEnded { ::prost::alloc::format!("penumbra.core.component.auction.v1.{}", Self::NAME) } } +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct EventDutchAuctionWithdrawn { + #[prost(message, optional, tag = "1")] + pub auction_id: ::core::option::Option, + #[prost(message, optional, tag = "2")] + pub state: ::core::option::Option, +} +impl ::prost::Name for EventDutchAuctionWithdrawn { + const NAME: &'static str = "EventDutchAuctionWithdrawn"; + const PACKAGE: &'static str = "penumbra.core.component.auction.v1"; + fn full_name() -> ::prost::alloc::string::String { + ::prost::alloc::format!("penumbra.core.component.auction.v1.{}", Self::NAME) + } +} /// A message emitted when value flows *into* the auction component. #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] diff --git a/crates/proto/src/gen/penumbra.core.component.auction.v1.serde.rs b/crates/proto/src/gen/penumbra.core.component.auction.v1.serde.rs index a4267c54cc..d9fa61ccf8 100644 --- a/crates/proto/src/gen/penumbra.core.component.auction.v1.serde.rs +++ b/crates/proto/src/gen/penumbra.core.component.auction.v1.serde.rs @@ -2404,6 +2404,119 @@ impl<'de> serde::Deserialize<'de> for EventDutchAuctionUpdated { deserializer.deserialize_struct("penumbra.core.component.auction.v1.EventDutchAuctionUpdated", FIELDS, GeneratedVisitor) } } +impl serde::Serialize for EventDutchAuctionWithdrawn { + #[allow(deprecated)] + fn serialize(&self, serializer: S) -> std::result::Result + where + S: serde::Serializer, + { + use serde::ser::SerializeStruct; + let mut len = 0; + if self.auction_id.is_some() { + len += 1; + } + if self.state.is_some() { + len += 1; + } + let mut struct_ser = serializer.serialize_struct("penumbra.core.component.auction.v1.EventDutchAuctionWithdrawn", len)?; + if let Some(v) = self.auction_id.as_ref() { + struct_ser.serialize_field("auctionId", v)?; + } + if let Some(v) = self.state.as_ref() { + struct_ser.serialize_field("state", v)?; + } + struct_ser.end() + } +} +impl<'de> serde::Deserialize<'de> for EventDutchAuctionWithdrawn { + #[allow(deprecated)] + fn deserialize(deserializer: D) -> std::result::Result + where + D: serde::Deserializer<'de>, + { + const FIELDS: &[&str] = &[ + "auction_id", + "auctionId", + "state", + ]; + + #[allow(clippy::enum_variant_names)] + enum GeneratedField { + AuctionId, + State, + __SkipField__, + } + impl<'de> serde::Deserialize<'de> for GeneratedField { + fn deserialize(deserializer: D) -> std::result::Result + 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(self, value: &str) -> std::result::Result + where + E: serde::de::Error, + { + match value { + "auctionId" | "auction_id" => Ok(GeneratedField::AuctionId), + "state" => Ok(GeneratedField::State), + _ => Ok(GeneratedField::__SkipField__), + } + } + } + deserializer.deserialize_identifier(GeneratedVisitor) + } + } + struct GeneratedVisitor; + impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { + type Value = EventDutchAuctionWithdrawn; + + fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter.write_str("struct penumbra.core.component.auction.v1.EventDutchAuctionWithdrawn") + } + + fn visit_map(self, mut map_: V) -> std::result::Result + where + V: serde::de::MapAccess<'de>, + { + let mut auction_id__ = None; + let mut state__ = None; + while let Some(k) = map_.next_key()? { + match k { + GeneratedField::AuctionId => { + if auction_id__.is_some() { + return Err(serde::de::Error::duplicate_field("auctionId")); + } + auction_id__ = map_.next_value()?; + } + GeneratedField::State => { + if state__.is_some() { + return Err(serde::de::Error::duplicate_field("state")); + } + state__ = map_.next_value()?; + } + GeneratedField::__SkipField__ => { + let _ = map_.next_value::()?; + } + } + } + Ok(EventDutchAuctionWithdrawn { + auction_id: auction_id__, + state: state__, + }) + } + } + deserializer.deserialize_struct("penumbra.core.component.auction.v1.EventDutchAuctionWithdrawn", FIELDS, GeneratedVisitor) + } +} impl serde::Serialize for EventValueCircuitBreakerCredit { #[allow(deprecated)] fn serialize(&self, serializer: S) -> std::result::Result diff --git a/crates/proto/src/gen/proto_descriptor.bin.no_lfs b/crates/proto/src/gen/proto_descriptor.bin.no_lfs index 36e6cbf46eaaa81a96f26e4ade360c49b6fdbe52..b9acf1c41423b47a554c340e0e4fdd0ffec7ec74 100644 GIT binary patch delta 631 zcmYL_%}OId6ova#S2{@}e3YzC}_k6@w< z4D>UIKM+EQ7(-~czQDNiRGY%Zg*tujckek}f2sa|t)BkF-jVyUuXM5_%kk+E)`t-5 z#!m#gGAwgA&H|%>?6i1 z>IWT#zSn^BtS_#yQ3^TPKyFs8(NJg%HTB;**5{fKeoFHrXPPK|*`(yMCdMb!MvAc6 z(z`XR>cbm&b1jIWJ_pl6v1%o`7N(}vO3Ddewsoh5rG-!k+HZe@f?yj(dr%N;n}geQ zANgJf&YRwOL~=yT<+UJl|Z|wHYWm*|ixcxw30BMCM*E%|Oun%AWN? wX?ivUCBdEz5ebG!(hxIz6HLBAvox_G*d>^p_4FCWD delta 485 zcmYL^y-EW?6ovQBPBw8s5+=JKDlx>w&cdGukRU2ZKqN09DA@S|LF{Z41tDXRB8{C{ zQwUr61|cjfgk{-uf|b36g=bcW6c^^qz2Cj(e5chxQoVYm(~j+*33Y#NZv>AW+AQ)9 z5*2lEOAA5&hCbQc+m6V~oMlZPPHJB8bVuFg;*nt7mClH)ccR6n>ig8_4yaakN%9dD z*2IC}++~*JWA)?H?iSt-1TiV*MNYRcIi~WGk+znV6>*q>Xol)}K>Gj*U`VX^KS{br zrK*ttLt3qiy$ocMN9yZ^n%gd80HYbm07g_Y7a71vUpz(_PdXE_rmE*ttL$NLLWM>a z!qXw*zYut1Wo$w~Vlp-%Ah9wwAv}FA(IHyviE)8X{cG$)0!fU0kHLPL*>B*DTj>nc c>r!JMU4ZFzdq^mTvQZqBLpecvn6F>{0_2fhvj6}9 diff --git a/proto/penumbra/penumbra/core/component/auction/v1/auction.proto b/proto/penumbra/penumbra/core/component/auction/v1/auction.proto index e3bce44ede..0f68deeb44 100755 --- a/proto/penumbra/penumbra/core/component/auction/v1/auction.proto +++ b/proto/penumbra/penumbra/core/component/auction/v1/auction.proto @@ -201,6 +201,11 @@ message EventDutchAuctionEnded { Reason reason = 3; } +message EventDutchAuctionWithdrawn { + AuctionId auction_id = 1; + DutchAuctionState state = 2; +} + // A message emitted when value flows *into* the auction component. message EventValueCircuitBreakerCredit { // The asset ID being deposited into the Auction component.