Skip to content

Commit

Permalink
proto: add extra SwapView fields (#3837)
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence authored Feb 16, 2024
1 parent fd46f26 commit 6ab2175
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/core/component/dex/src/swap/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl From<SwapView> for pb::SwapView {
swap_plaintext: Some(swap_plaintext.into()),
// Swap claim crossreferencing is not yet supported in the Rust stack.
claim_tx: None,
// These fields are also not yet supported in the Rust stack.
asset_1_metadata: None,
asset_2_metadata: None,
batch_swap_output_data: None,
output_1: None,
output_2: None,
})),
},
SwapView::Opaque { swap } => Self {
Expand Down
31 changes: 31 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 @@ -259,6 +259,37 @@ pub mod swap_view {
pub claim_tx: ::core::option::Option<
super::super::super::super::txhash::v1::TransactionId,
>,
/// Optionally, if the swap has been confirmed, the batch price it received.
///
/// As soon as the swap is detected, the view server can in principle record
/// the relevant BSOD and provide it as part of the view. This allows providing
/// info about the execution of the swap.
#[prost(message, optional, tag = "20")]
pub batch_swap_output_data: ::core::option::Option<super::BatchSwapOutputData>,
/// Optionally, if the swap has been confirmed, the output note of asset 1.
///
/// This is the note that will be minted by the SwapClaim action.
#[prost(message, optional, tag = "30")]
pub output_1: ::core::option::Option<
super::super::super::shielded_pool::v1::NoteView,
>,
/// Optionally, if the swap has been confirmed, the output note of asset 2.
///
/// This is the note that will be minted by the SwapClaim action.
#[prost(message, optional, tag = "31")]
pub output_2: ::core::option::Option<
super::super::super::shielded_pool::v1::NoteView,
>,
/// Optionally, metadata about asset 1 in the `swap`'s trading pair.
#[prost(message, optional, tag = "40")]
pub asset_1_metadata: ::core::option::Option<
super::super::super::super::asset::v1::Metadata,
>,
/// Optionally, metadata about asset 2 in the `swap`'s trading pair.
#[prost(message, optional, tag = "41")]
pub asset_2_metadata: ::core::option::Option<
super::super::super::super::asset::v1::Metadata,
>,
}
impl ::prost::Name for Visible {
const NAME: &'static str = "Visible";
Expand Down
90 changes: 90 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 @@ -7635,6 +7635,21 @@ impl serde::Serialize for swap_view::Visible {
if self.claim_tx.is_some() {
len += 1;
}
if self.batch_swap_output_data.is_some() {
len += 1;
}
if self.output_1.is_some() {
len += 1;
}
if self.output_2.is_some() {
len += 1;
}
if self.asset_1_metadata.is_some() {
len += 1;
}
if self.asset_2_metadata.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.component.dex.v1.SwapView.Visible", len)?;
if let Some(v) = self.swap.as_ref() {
struct_ser.serialize_field("swap", v)?;
Expand All @@ -7645,6 +7660,21 @@ impl serde::Serialize for swap_view::Visible {
if let Some(v) = self.claim_tx.as_ref() {
struct_ser.serialize_field("claimTx", v)?;
}
if let Some(v) = self.batch_swap_output_data.as_ref() {
struct_ser.serialize_field("batchSwapOutputData", v)?;
}
if let Some(v) = self.output_1.as_ref() {
struct_ser.serialize_field("output1", v)?;
}
if let Some(v) = self.output_2.as_ref() {
struct_ser.serialize_field("output2", v)?;
}
if let Some(v) = self.asset_1_metadata.as_ref() {
struct_ser.serialize_field("asset1Metadata", v)?;
}
if let Some(v) = self.asset_2_metadata.as_ref() {
struct_ser.serialize_field("asset2Metadata", v)?;
}
struct_ser.end()
}
}
Expand All @@ -7660,13 +7690,28 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
"swapPlaintext",
"claim_tx",
"claimTx",
"batch_swap_output_data",
"batchSwapOutputData",
"output_1",
"output1",
"output_2",
"output2",
"asset_1_metadata",
"asset1Metadata",
"asset_2_metadata",
"asset2Metadata",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
Swap,
SwapPlaintext,
ClaimTx,
BatchSwapOutputData,
Output1,
Output2,
Asset1Metadata,
Asset2Metadata,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand All @@ -7692,6 +7737,11 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
"swap" => Ok(GeneratedField::Swap),
"swapPlaintext" | "swap_plaintext" => Ok(GeneratedField::SwapPlaintext),
"claimTx" | "claim_tx" => Ok(GeneratedField::ClaimTx),
"batchSwapOutputData" | "batch_swap_output_data" => Ok(GeneratedField::BatchSwapOutputData),
"output1" | "output_1" => Ok(GeneratedField::Output1),
"output2" | "output_2" => Ok(GeneratedField::Output2),
"asset1Metadata" | "asset_1_metadata" => Ok(GeneratedField::Asset1Metadata),
"asset2Metadata" | "asset_2_metadata" => Ok(GeneratedField::Asset2Metadata),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand All @@ -7714,6 +7764,11 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
let mut swap__ = None;
let mut swap_plaintext__ = None;
let mut claim_tx__ = None;
let mut batch_swap_output_data__ = None;
let mut output_1__ = None;
let mut output_2__ = None;
let mut asset_1_metadata__ = None;
let mut asset_2_metadata__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::Swap => {
Expand All @@ -7734,6 +7789,36 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
}
claim_tx__ = map_.next_value()?;
}
GeneratedField::BatchSwapOutputData => {
if batch_swap_output_data__.is_some() {
return Err(serde::de::Error::duplicate_field("batchSwapOutputData"));
}
batch_swap_output_data__ = map_.next_value()?;
}
GeneratedField::Output1 => {
if output_1__.is_some() {
return Err(serde::de::Error::duplicate_field("output1"));
}
output_1__ = map_.next_value()?;
}
GeneratedField::Output2 => {
if output_2__.is_some() {
return Err(serde::de::Error::duplicate_field("output2"));
}
output_2__ = map_.next_value()?;
}
GeneratedField::Asset1Metadata => {
if asset_1_metadata__.is_some() {
return Err(serde::de::Error::duplicate_field("asset1Metadata"));
}
asset_1_metadata__ = map_.next_value()?;
}
GeneratedField::Asset2Metadata => {
if asset_2_metadata__.is_some() {
return Err(serde::de::Error::duplicate_field("asset2Metadata"));
}
asset_2_metadata__ = map_.next_value()?;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -7743,6 +7828,11 @@ impl<'de> serde::Deserialize<'de> for swap_view::Visible {
swap: swap__,
swap_plaintext: swap_plaintext__,
claim_tx: claim_tx__,
batch_swap_output_data: batch_swap_output_data__,
output_1: output_1__,
output_2: output_2__,
asset_1_metadata: asset_1_metadata__,
asset_2_metadata: asset_2_metadata__,
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
18 changes: 18 additions & 0 deletions proto/penumbra/penumbra/core/component/dex/v1/dex.proto
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ message SwapView {
// This field allows frontends to more easily crossreference the sequence of
// Swap/SwapClaim actions.
txhash.v1.TransactionId claim_tx = 4;
// Optionally, if the swap has been confirmed, the batch price it received.
//
// As soon as the swap is detected, the view server can in principle record
// the relevant BSOD and provide it as part of the view. This allows providing
// info about the execution of the swap.
BatchSwapOutputData batch_swap_output_data = 20;
// Optionally, if the swap has been confirmed, the output note of asset 1.
//
// This is the note that will be minted by the SwapClaim action.
shielded_pool.v1.NoteView output_1 = 30;
// Optionally, if the swap has been confirmed, the output note of asset 2.
//
// This is the note that will be minted by the SwapClaim action.
shielded_pool.v1.NoteView output_2 = 31;
// Optionally, metadata about asset 1 in the `swap`'s trading pair.
asset.v1.Metadata asset_1_metadata = 40;
// Optionally, metadata about asset 2 in the `swap`'s trading pair.
asset.v1.Metadata asset_2_metadata = 41;
}

message Opaque {
Expand Down

0 comments on commit 6ab2175

Please sign in to comment.