Skip to content

Commit

Permalink
Add a Position to EventPositionOpen (#4755)
Browse files Browse the repository at this point in the history
This is necessary because at no other point in the related chain of
events do we ever see the full position, and we need to see the full
position to get information such as the price.

We could simply add in the price, but it's more conservative to simply
emit the entire position, in case there's anything else we might've
forgotten about.

## 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 adds new data to events.
  • Loading branch information
cronokirby authored Jul 24, 2024
1 parent 53b8338 commit e6883fa
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
1 change: 1 addition & 0 deletions crates/core/component/dex/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn position_open(position: &Position) -> pb::EventPositionOpen {
reserves_1: Some(position.reserves.r1.into()),
reserves_2: Some(position.reserves.r2.into()),
trading_fee: position.phi.component.fee,
position: Some(position.clone().into()),
}
}

Expand Down
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 @@ -1377,6 +1377,11 @@ pub struct EventPositionOpen {
/// e.g. 2% fee is expressed as 200, 100% fee is expressed as 10000;
#[prost(uint32, tag = "5")]
pub trading_fee: u32,
/// The full position.
///
/// This is somewhat redundant, but contains any information not present above.
#[prost(message, optional, tag = "6")]
pub position: ::core::option::Option<Position>,
}
impl ::prost::Name for EventPositionOpen {
const NAME: &'static str = "EventPositionOpen";
Expand Down
17 changes: 17 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 @@ -2547,6 +2547,9 @@ impl serde::Serialize for EventPositionOpen {
if self.trading_fee != 0 {
len += 1;
}
if self.position.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.component.dex.v1.EventPositionOpen", len)?;
if let Some(v) = self.position_id.as_ref() {
struct_ser.serialize_field("positionId", v)?;
Expand All @@ -2563,6 +2566,9 @@ impl serde::Serialize for EventPositionOpen {
if self.trading_fee != 0 {
struct_ser.serialize_field("tradingFee", &self.trading_fee)?;
}
if let Some(v) = self.position.as_ref() {
struct_ser.serialize_field("position", v)?;
}
struct_ser.end()
}
}
Expand All @@ -2583,6 +2589,7 @@ impl<'de> serde::Deserialize<'de> for EventPositionOpen {
"reserves2",
"trading_fee",
"tradingFee",
"position",
];

#[allow(clippy::enum_variant_names)]
Expand All @@ -2592,6 +2599,7 @@ impl<'de> serde::Deserialize<'de> for EventPositionOpen {
Reserves1,
Reserves2,
TradingFee,
Position,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand Down Expand Up @@ -2619,6 +2627,7 @@ impl<'de> serde::Deserialize<'de> for EventPositionOpen {
"reserves1" | "reserves_1" => Ok(GeneratedField::Reserves1),
"reserves2" | "reserves_2" => Ok(GeneratedField::Reserves2),
"tradingFee" | "trading_fee" => Ok(GeneratedField::TradingFee),
"position" => Ok(GeneratedField::Position),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand All @@ -2643,6 +2652,7 @@ impl<'de> serde::Deserialize<'de> for EventPositionOpen {
let mut reserves_1__ = None;
let mut reserves_2__ = None;
let mut trading_fee__ = None;
let mut position__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::PositionId => {
Expand Down Expand Up @@ -2677,6 +2687,12 @@ impl<'de> serde::Deserialize<'de> for EventPositionOpen {
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::Position => {
if position__.is_some() {
return Err(serde::de::Error::duplicate_field("position"));
}
position__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -2688,6 +2704,7 @@ impl<'de> serde::Deserialize<'de> for EventPositionOpen {
reserves_1: reserves_1__,
reserves_2: reserves_2__,
trading_fee: trading_fee__.unwrap_or_default(),
position: position__,
})
}
}
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 @@ -655,6 +655,10 @@ message EventPositionOpen {
// The trading fee for the position, expressed in basis points.
// e.g. 2% fee is expressed as 200, 100% fee is expressed as 10000;
uint32 trading_fee = 5;
// The full position.
//
// This is somewhat redundant, but contains any information not present above.
Position position = 6;
}

message EventPositionClose {
Expand Down

0 comments on commit e6883fa

Please sign in to comment.