-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auction: add
ActionDutchAuctionWithdraw
and action views (#4213)
## 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
Showing
11 changed files
with
702 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
9 changes: 9 additions & 0 deletions
9
crates/core/component/auction/src/auction/dutch/actions/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
68 changes: 68 additions & 0 deletions
68
crates/core/component/auction/src/auction/dutch/actions/schedule_view.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()?, | ||
}) | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
crates/core/component/auction/src/auction/dutch/actions/withdraw.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()?, | ||
}) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
crates/core/component/auction/src/auction/dutch/actions/withdraw_view.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<_, _>>()?, | ||
}) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
crates/core/component/auction/src/component/action_handler/dutch/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod end; | ||
mod schedule; | ||
mod withdraw; |
18 changes: 18 additions & 0 deletions
18
crates/core/component/auction/src/component/action_handler/dutch/withdraw.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.