From 158fd06726e5ba5cdad5eb019021e233eb99c72e Mon Sep 17 00:00:00 2001 From: Lucas Meier Date: Thu, 24 Oct 2024 21:40:50 -0700 Subject: [PATCH 1/2] Add a command to query all open positions in a PCLI wallet Closes #4825. --- crates/bin/pcli/src/command/view.rs | 6 ++++ crates/bin/pcli/src/command/view/lps.rs | 48 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 crates/bin/pcli/src/command/view/lps.rs diff --git a/crates/bin/pcli/src/command/view.rs b/crates/bin/pcli/src/command/view.rs index 0bc07a2d85..4f25d6c2aa 100644 --- a/crates/bin/pcli/src/command/view.rs +++ b/crates/bin/pcli/src/command/view.rs @@ -2,6 +2,7 @@ use anyhow::Result; use address::AddressCmd; use balance::BalanceCmd; +use lps::LpsCmd; use noble_address::NobleAddressCmd; use staked::StakedCmd; use transaction_hashes::TransactionHashesCmd; @@ -15,6 +16,7 @@ use self::auction::AuctionCmd; mod address; mod auction; mod balance; +mod lps; mod noble_address; mod staked; mod wallet_id; @@ -48,6 +50,8 @@ pub enum ViewCmd { ListTransactionHashes(TransactionHashesCmd), /// Displays a transaction's details by hash. Tx(TxCmd), + /// View information about the liquidity positions you control. + Lps(LpsCmd), } impl ViewCmd { @@ -63,6 +67,7 @@ impl ViewCmd { ViewCmd::Sync => false, ViewCmd::ListTransactionHashes(transactions_cmd) => transactions_cmd.offline(), ViewCmd::Tx(tx_cmd) => tx_cmd.offline(), + ViewCmd::Lps(lps_cmd) => lps_cmd.offline(), } } @@ -110,6 +115,7 @@ impl ViewCmd { .exec(&full_viewing_key, view_client, channel) .await?; } + ViewCmd::Lps(cmd) => cmd.exec(app).await?, } Ok(()) diff --git a/crates/bin/pcli/src/command/view/lps.rs b/crates/bin/pcli/src/command/view/lps.rs new file mode 100644 index 0000000000..3761442f39 --- /dev/null +++ b/crates/bin/pcli/src/command/view/lps.rs @@ -0,0 +1,48 @@ +use anyhow::{anyhow, Result}; +use futures::stream::TryStreamExt; +use penumbra_dex::lp::position::{Position, State}; +use penumbra_proto::core::component::dex::v1::{ + query_service_client::QueryServiceClient as DexQueryServiceClient, + LiquidityPositionsByIdRequest, +}; +use penumbra_view::ViewClient; + +use crate::{command::utils, App}; + +#[derive(Debug, clap::Args)] +pub struct LpsCmd {} + +impl LpsCmd { + pub fn offline(&self) -> bool { + false + } + + pub async fn exec(&self, app: &mut App) -> Result<()> { + let my_position_ids = app + .view() + .owned_position_ids(Some(State::Opened), None) + .await?; + let mut dex_client = DexQueryServiceClient::new(app.pd_channel().await?); + + let positions_stream = dex_client + .liquidity_positions_by_id(LiquidityPositionsByIdRequest { + position_id: my_position_ids.into_iter().map(Into::into).collect(), + }) + .await? + .into_inner() + .map_err(|e| anyhow!("eror fetching liquidity positions: {}", e)) + .and_then(|msg| async move { + msg.data + .ok_or_else(|| anyhow!("missing liquidity position in response")) + .map(Position::try_from)? + }); + + let asset_cache = app.view().assets().await?; + + let positions = positions_stream.try_collect::>().await?; + + println!("{}", utils::render_positions(&asset_cache, &positions)); + + Ok(()) + } +} From b1cf959ed6e83ba26aed1dd0c8bb5825cd9e8305 Mon Sep 17 00:00:00 2001 From: Conor Schaefer Date: Fri, 25 Oct 2024 10:11:43 -0700 Subject: [PATCH 2/2] feat: use full name "liquidity-positions" in pcli Preserves the more convenient "lps" as an alias, which it is. --- crates/bin/pcli/src/command/view.rs | 9 +++++---- crates/bin/pcli/src/command/view/lps.rs | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/bin/pcli/src/command/view.rs b/crates/bin/pcli/src/command/view.rs index 4f25d6c2aa..d0477799d6 100644 --- a/crates/bin/pcli/src/command/view.rs +++ b/crates/bin/pcli/src/command/view.rs @@ -2,7 +2,7 @@ use anyhow::Result; use address::AddressCmd; use balance::BalanceCmd; -use lps::LpsCmd; +use lps::LiquidityPositionsCmd; use noble_address::NobleAddressCmd; use staked::StakedCmd; use transaction_hashes::TransactionHashesCmd; @@ -51,7 +51,8 @@ pub enum ViewCmd { /// Displays a transaction's details by hash. Tx(TxCmd), /// View information about the liquidity positions you control. - Lps(LpsCmd), + #[clap(visible_alias = "lps")] + LiquidityPositions(LiquidityPositionsCmd), } impl ViewCmd { @@ -67,7 +68,7 @@ impl ViewCmd { ViewCmd::Sync => false, ViewCmd::ListTransactionHashes(transactions_cmd) => transactions_cmd.offline(), ViewCmd::Tx(tx_cmd) => tx_cmd.offline(), - ViewCmd::Lps(lps_cmd) => lps_cmd.offline(), + ViewCmd::LiquidityPositions(lps_cmd) => lps_cmd.offline(), } } @@ -115,7 +116,7 @@ impl ViewCmd { .exec(&full_viewing_key, view_client, channel) .await?; } - ViewCmd::Lps(cmd) => cmd.exec(app).await?, + ViewCmd::LiquidityPositions(cmd) => cmd.exec(app).await?, } Ok(()) diff --git a/crates/bin/pcli/src/command/view/lps.rs b/crates/bin/pcli/src/command/view/lps.rs index 3761442f39..0fae70c640 100644 --- a/crates/bin/pcli/src/command/view/lps.rs +++ b/crates/bin/pcli/src/command/view/lps.rs @@ -10,9 +10,9 @@ use penumbra_view::ViewClient; use crate::{command::utils, App}; #[derive(Debug, clap::Args)] -pub struct LpsCmd {} +pub struct LiquidityPositionsCmd {} -impl LpsCmd { +impl LiquidityPositionsCmd { pub fn offline(&self) -> bool { false }