-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a command to query all open positions in a PCLI wallet (#4904)
Closes #4825. ## Describe your changes This adds a command: `pcli v lps` which displays all open liquidity positions owned by the wallet. To test, try, e.g: ``` pcli tx position replicate linear --lower -price 0.4 --upper-price 0.8 penumbra:gm 100gm --current-price 0.5 pcli v lps ``` ## Checklist before requesting a review - [x] I have added guiding text to explain how a reviewer should test these changes. - [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: > PCLI only. --------- Co-authored-by: Conor Schaefer <[email protected]>
- Loading branch information
1 parent
c23270b
commit fcce631
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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
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,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 LiquidityPositionsCmd {} | ||
|
||
impl LiquidityPositionsCmd { | ||
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::<Vec<_>>().await?; | ||
|
||
println!("{}", utils::render_positions(&asset_cache, &positions)); | ||
|
||
Ok(()) | ||
} | ||
} |