Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcli: support multiple lp withdrawals #5070

Open
wants to merge 1 commit into
base: protocol/lqt_branch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions crates/bin/pcli/src/command/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use regex::Regex;

use liquidity_position::PositionCmd;
use penumbra_sdk_asset::{asset, asset::Metadata, Value, STAKING_TOKEN_ASSET_ID};
use penumbra_sdk_dex::{lp::position, swap_claim::SwapClaimPlan};
use penumbra_sdk_dex::{
lp::position::{self, Position, State},
swap_claim::SwapClaimPlan,
};
use penumbra_sdk_fee::FeeTier;
use penumbra_sdk_governance::{
proposal::ProposalToml, proposal_state::State as ProposalState, Vote,
Expand Down Expand Up @@ -1376,6 +1379,7 @@ impl TxCmd {
*position_id,
reserves.try_into().expect("invalid reserves"),
pair.try_into().expect("invalid pair"),
0,
);
}

Expand Down Expand Up @@ -1404,28 +1408,36 @@ impl TxCmd {

for position_id in position_ids {
// Fetch the information regarding the position from the view service.
let position = client
let response = client
.liquidity_position_by_id(LiquidityPositionByIdRequest {
position_id: Some(PositionId::from(*position_id)),
})
.await?
.into_inner();

let reserves = position
.data
.clone()
.expect("missing position metadata")
.reserves
.expect("missing position reserves");
let pair = position
let position: Position = response
.data
.expect("missing position")
.phi
.expect("missing position trading function")
.pair
.expect("missing trading function pair");
.try_into()
.expect("invalid position state");

let reserves = position.reserves;
let pair = position.phi.pair;
let prev_seq = match position.state {
State::Withdrawn { sequence } => sequence,
_ => {
anyhow::bail!("position {} is not in a withdrawable state", position_id)
}
};

let next_seq = prev_seq + 1;

planner.position_withdraw(*position_id, reserves.try_into()?, pair.try_into()?);
planner.position_withdraw(
*position_id,
reserves.try_into()?,
pair.try_into()?,
next_seq,
);
}

let plan = planner
Expand Down
3 changes: 2 additions & 1 deletion crates/view/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ impl<R: RngCore + CryptoRng> Planner<R> {
position_id: position::Id,
reserves: Reserves,
pair: TradingPair,
next_sequence: u64,
) -> &mut Self {
self.action_list.push(PositionWithdrawPlan {
reserves,
position_id,
pair,
sequence: 0,
sequence: next_sequence,
rewards: Vec::new(),
});
self
Expand Down
2 changes: 1 addition & 1 deletion crates/view/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ impl ViewService for ViewServer {
tonic::Status::invalid_argument(format!("Could not parse pair: {e:#}"))
})?;

planner.position_withdraw(position_id, reserves, trading_pair);
planner.position_withdraw(position_id, reserves, trading_pair, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being 0 ok? Wouldn't we want to follow the planning request?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of a fake TPR implementation, unlike the one in Prax. It's not used by the regular pcli commands, I think an integration test uses it maybe. Making it work here is possible but low ROI, so I opted for not doing anything

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good ; we could maybe add a comment to that effect

}

// Insert any ICS20 withdrawals.
Expand Down
Loading