Skip to content

Commit

Permalink
auction: add ActionDutchAuctionWithdraw and action views (#4213)
Browse files Browse the repository at this point in the history
## Describe your changes

Adds the skeleton for the `Withdraw`-related Dutch auction proto and
domain types.

## Issue ticket number and link

#4206 

## 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:

  > isolated to auctions component and not hooked up to the app
  • Loading branch information
zbuc authored Apr 15, 2024
1 parent aecb67f commit ea0ecbe
Show file tree
Hide file tree
Showing 11 changed files with 702 additions and 0 deletions.
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
pub mod schedule;
pub use schedule::ActionDutchAuctionSchedule;

pub mod schedule_view;
pub use schedule_view::ActionDutchAuctionScheduleView;

pub mod end;
pub use end::ActionDutchAuctionEnd;

pub mod withdraw;
pub use withdraw::ActionDutchAuctionWithdraw;

pub mod withdraw_view;
pub use withdraw_view::ActionDutchAuctionWithdrawView;
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use crate::auction::{
dutch::{actions::ActionDutchAuctionSchedule, asset::Metadata},
id::AuctionId,
};
use anyhow::anyhow;
use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(
try_from = "pb::ActionDutchAuctionScheduleView",
into = "pb::ActionDutchAuctionScheduleView"
)]
pub struct ActionDutchAuctionScheduleView {
pub action: ActionDutchAuctionSchedule,
pub auction_id: AuctionId,
pub input_metadata: Metadata,
pub output_metadata: Metadata,
}

/* Protobuf impls */
impl DomainType for ActionDutchAuctionScheduleView {
type Proto = pb::ActionDutchAuctionScheduleView;
}

impl From<ActionDutchAuctionScheduleView> for pb::ActionDutchAuctionScheduleView {
fn from(domain: ActionDutchAuctionScheduleView) -> Self {
pb::ActionDutchAuctionScheduleView {
action: Some(domain.action.into()),
auction_id: Some(domain.auction_id.into()),
input_metadata: Some(domain.input_metadata.into()),
output_metadata: Some(domain.output_metadata.into()),
}
}
}

impl TryFrom<pb::ActionDutchAuctionScheduleView> for ActionDutchAuctionScheduleView {
type Error = anyhow::Error;

fn try_from(msg: pb::ActionDutchAuctionScheduleView) -> Result<Self, Self::Error> {
Ok(ActionDutchAuctionScheduleView {
action: msg
.action
.ok_or_else(|| {
anyhow!("ActionDutchAuctionScheduleView message is missing an action")
})?
.try_into()?,
auction_id: msg
.auction_id
.ok_or_else(|| {
anyhow!("ActionDutchAuctionScheduleView message is missing an auction_id")
})?
.try_into()?,
input_metadata: msg
.input_metadata
.ok_or_else(|| {
anyhow!("ActionDutchAuctionScheduleView message is missing an input_metadata")
})?
.try_into()?,
output_metadata: msg
.output_metadata
.ok_or_else(|| {
anyhow!("ActionDutchAuctionScheduleView message is missing an output_metadata")
})?
.try_into()?,
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use crate::auction::id::AuctionId;
use anyhow::anyhow;
use penumbra_asset::balance;
use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(
try_from = "pb::ActionDutchAuctionWithdraw",
into = "pb::ActionDutchAuctionWithdraw"
)]
pub struct ActionDutchAuctionWithdraw {
pub auction_id: AuctionId,
pub seq: u64,
pub reserves_commitment: balance::Commitment,
}

/* Protobuf impls */
impl DomainType for ActionDutchAuctionWithdraw {
type Proto = pb::ActionDutchAuctionWithdraw;
}

impl From<ActionDutchAuctionWithdraw> for pb::ActionDutchAuctionWithdraw {
fn from(domain: ActionDutchAuctionWithdraw) -> Self {
pb::ActionDutchAuctionWithdraw {
auction_id: Some(domain.auction_id.into()),
seq: domain.seq,
reserves_commitment: Some(domain.reserves_commitment.into()),
}
}
}

impl TryFrom<pb::ActionDutchAuctionWithdraw> for ActionDutchAuctionWithdraw {
type Error = anyhow::Error;

fn try_from(msg: pb::ActionDutchAuctionWithdraw) -> Result<Self, Self::Error> {
Ok(ActionDutchAuctionWithdraw {
auction_id: msg
.auction_id
.ok_or_else(|| {
anyhow!("ActionDutchAuctionWithdraw message is missing an auction_id")
})?
.try_into()?,
seq: msg.seq,
reserves_commitment: msg
.reserves_commitment
.ok_or_else(|| {
anyhow!("ActionDutchAuctionWithdraw message is missing reserves_commitment")
})?
.try_into()?,
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::auction::dutch::actions::ActionDutchAuctionWithdraw;
use anyhow::anyhow;
use penumbra_asset::ValueView;
use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(
try_from = "pb::ActionDutchAuctionWithdrawView",
into = "pb::ActionDutchAuctionWithdrawView"
)]
pub struct ActionDutchAuctionWithdrawView {
pub action: ActionDutchAuctionWithdraw,
// A sequence of values that sum together to the provided
// reserves commitment.
pub reserves: Vec<ValueView>,
}

/* Protobuf impls */
impl DomainType for ActionDutchAuctionWithdrawView {
type Proto = pb::ActionDutchAuctionWithdrawView;
}

impl From<ActionDutchAuctionWithdrawView> for pb::ActionDutchAuctionWithdrawView {
fn from(domain: ActionDutchAuctionWithdrawView) -> Self {
pb::ActionDutchAuctionWithdrawView {
action: Some(domain.action.into()),
reserves: domain
.reserves
.into_iter()
.map(Into::into)
.collect::<Vec<_>>(),
}
}
}

impl TryFrom<pb::ActionDutchAuctionWithdrawView> for ActionDutchAuctionWithdrawView {
type Error = anyhow::Error;

fn try_from(msg: pb::ActionDutchAuctionWithdrawView) -> Result<Self, Self::Error> {
Ok(ActionDutchAuctionWithdrawView {
action: msg
.action
.ok_or_else(|| {
anyhow!("ActionDutchAuctionWithdrawView message is missing an action")
})?
.try_into()?,
reserves: msg
.reserves
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
})
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod end;
mod schedule;
mod withdraw;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use anyhow::Result;
use async_trait::async_trait;
use cnidarium::StateWrite;
use cnidarium_component::ActionHandler;

use crate::auction::dutch::actions::ActionDutchAuctionWithdraw;

#[async_trait]
impl ActionHandler for ActionDutchAuctionWithdraw {
type CheckStatelessContext = ();
async fn check_stateless(&self, _context: ()) -> Result<()> {
Ok(())
}

async fn check_and_execute<S: StateWrite>(&self, mut _state: S) -> Result<()> {
Ok(())
}
}
73 changes: 73 additions & 0 deletions crates/proto/src/gen/penumbra.core.component.auction.v1alpha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,79 @@ impl ::prost::Name for ActionDutchAuctionEnd {
)
}
}
/// Withdraw funds from the ended auction associated with the specified `auction_id`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ActionDutchAuctionWithdraw {
/// The auction to withdraw funds from.
#[prost(message, optional, tag = "1")]
pub auction_id: ::core::option::Option<AuctionId>,
/// The sequence number of the withdrawal.
#[prost(uint64, tag = "2")]
pub seq: u64,
/// A transparent (zero blinding factor) commitment to the
/// auction's final reserves.
///
/// The chain will check this commitment by recomputing it
/// with the on-chain state.
#[prost(message, optional, tag = "3")]
pub reserves_commitment: ::core::option::Option<
super::super::super::asset::v1::BalanceCommitment,
>,
}
impl ::prost::Name for ActionDutchAuctionWithdraw {
const NAME: &'static str = "ActionDutchAuctionWithdraw";
const PACKAGE: &'static str = "penumbra.core.component.auction.v1alpha1";
fn full_name() -> ::prost::alloc::string::String {
::prost::alloc::format!(
"penumbra.core.component.auction.v1alpha1.{}", Self::NAME
)
}
}
/// An `ActionDutchAuctionWithdraw` augmented with additional metadata.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ActionDutchAuctionWithdrawView {
#[prost(message, optional, tag = "1")]
pub action: ::core::option::Option<ActionDutchAuctionWithdraw>,
/// A sequence of values that sum together to the provided
/// reserves commitment.
#[prost(message, repeated, tag = "2")]
pub reserves: ::prost::alloc::vec::Vec<super::super::super::asset::v1::ValueView>,
}
impl ::prost::Name for ActionDutchAuctionWithdrawView {
const NAME: &'static str = "ActionDutchAuctionWithdrawView";
const PACKAGE: &'static str = "penumbra.core.component.auction.v1alpha1";
fn full_name() -> ::prost::alloc::string::String {
::prost::alloc::format!(
"penumbra.core.component.auction.v1alpha1.{}", Self::NAME
)
}
}
/// An `ActionDutchAuctionSchedule` augmented with additional metadata.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ActionDutchAuctionScheduleView {
#[prost(message, optional, tag = "1")]
pub action: ::core::option::Option<ActionDutchAuctionSchedule>,
#[prost(message, optional, tag = "2")]
pub auction_id: ::core::option::Option<AuctionId>,
#[prost(message, optional, tag = "3")]
pub input_metadata: ::core::option::Option<super::super::super::asset::v1::Metadata>,
#[prost(message, optional, tag = "4")]
pub output_metadata: ::core::option::Option<
super::super::super::asset::v1::Metadata,
>,
}
impl ::prost::Name for ActionDutchAuctionScheduleView {
const NAME: &'static str = "ActionDutchAuctionScheduleView";
const PACKAGE: &'static str = "penumbra.core.component.auction.v1alpha1";
fn full_name() -> ::prost::alloc::string::String {
::prost::alloc::format!(
"penumbra.core.component.auction.v1alpha1.{}", Self::NAME
)
}
}
/// Generated client implementations.
#[cfg(feature = "rpc")]
pub mod query_service_client {
Expand Down
Loading

0 comments on commit ea0ecbe

Please sign in to comment.