pcli/command/view/
auction.rs1use anyhow::Result;
2use comfy_table::{presets, Cell, ContentArrangement, Table};
3use penumbra_sdk_auction::auction::dutch::DutchAuction;
4use penumbra_sdk_keys::FullViewingKey;
5use penumbra_sdk_proto::{core::component::auction::v1 as pb_auction, DomainType, Name};
6use penumbra_sdk_view::ViewClient;
7
8use crate::command::query::auction::render_dutch_auction;
9
10#[derive(Debug, clap::Args)]
11pub struct AuctionCmd {
12 #[clap(long)]
13 pub include_inactive: bool,
15 #[clap(long, default_value_t = true)]
17 pub query_latest_state: bool,
18}
19
20impl AuctionCmd {
21 pub fn offline(&self) -> bool {
22 false
23 }
24
25 pub async fn exec(
26 &self,
27 view_client: &mut impl ViewClient,
28 _fvk: &FullViewingKey,
29 ) -> Result<()> {
30 let auctions: Vec<(
31 penumbra_sdk_auction::auction::AuctionId,
32 penumbra_sdk_view::SpendableNoteRecord,
33 u64,
34 Option<pbjson_types::Any>,
35 Vec<penumbra_sdk_dex::lp::position::Position>,
36 )> = view_client
37 .auctions(None, self.include_inactive, self.query_latest_state)
38 .await?;
39
40 for (auction_id, _, local_seq, maybe_auction_state, positions) in auctions.into_iter() {
41 if let Some(pb_auction_state) = maybe_auction_state {
42 if pb_auction_state.type_url == pb_auction::DutchAuction::type_url() {
43 let dutch_auction = DutchAuction::decode(pb_auction_state.value)
44 .expect("no deserialization error");
45 let asset_cache = view_client.assets().await?;
46 render_dutch_auction(
47 &asset_cache,
48 &dutch_auction,
49 Some(local_seq),
50 positions.get(0).cloned(),
51 )
52 .await
53 .expect("no rendering errors");
54 } else {
55 unimplemented!("only supporting dutch auctions at the moment, come back later");
56 }
57 } else {
58 let position_ids: Vec<String> = positions
59 .into_iter()
60 .map(|lp: penumbra_sdk_dex::lp::position::Position| format!("{}", lp.id()))
61 .collect();
62
63 let mut auction_table = Table::new();
64 auction_table.load_preset(presets::ASCII_FULL);
65 auction_table
66 .set_header(vec!["Auction id", "LPs"])
67 .set_content_arrangement(ContentArrangement::DynamicFullWidth)
68 .add_row(vec![
69 Cell::new(&auction_id).set_delimiter('.'),
70 Cell::new(format!("{:?}", position_ids))
71 .set_alignment(comfy_table::CellAlignment::Center),
72 ]);
73
74 println!("{auction_table}");
75 }
76 }
77 Ok(())
78 }
79}