Skip to content

Commit

Permalink
Add an event for auction withdrawals (#4612)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cronokirby committed Jun 13, 2024
1 parent b584c26 commit 5793168
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/core/component/auction/src/component/dutch_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions crates/core/component/auction/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions crates/proto/src/gen/penumbra.core.component.auction.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuctionId>,
#[prost(message, optional, tag = "2")]
pub state: ::core::option::Option<DutchAuctionState>,
}
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)]
Expand Down
113 changes: 113 additions & 0 deletions crates/proto/src/gen/penumbra.core.component.auction.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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.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<D>(deserializer: D) -> std::result::Result<Self, D::Error>
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<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 {
"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<V>(self, mut map_: V) -> std::result::Result<EventDutchAuctionWithdrawn, V::Error>
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::<serde::de::IgnoredAny>()?;
}
}
}
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<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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5793168

Please sign in to comment.