Skip to content

Commit

Permalink
refactor: make lp withdraw action to take multiple position IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed May 28, 2024
1 parent 894346a commit b64e91c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
57 changes: 31 additions & 26 deletions crates/bin/pcli/src/command/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use regex::Regex;

use liquidity_position::PositionCmd;
use penumbra_asset::{asset, asset::Metadata, Value, STAKING_TOKEN_ASSET_ID};
use penumbra_dex::lp::position::Id;
use penumbra_dex::{lp::position, swap_claim::SwapClaimPlan};
use penumbra_governance::{proposal::ProposalToml, proposal_state::State as ProposalState, Vote};
use penumbra_keys::{keys::AddressIndex, Address};
Expand Down Expand Up @@ -1236,44 +1235,50 @@ impl TxCmd {
}
TxCmd::Position(PositionCmd::Withdraw {
source,
position_id,
position_ids,
fee_tier,
}) => {
let mut client = DexQueryServiceClient::new(app.pd_channel().await?);

// Fetch the information regarding the position from the view service.
let position = client
.liquidity_position_by_id(LiquidityPositionByIdRequest {
position_id: Some(PositionId::from(*position_id)),
})
.await?
.into_inner();
let planner = Planner::new(OsRng)
.set_gas_prices(gas_prices)
.set_fee_tier((*fee_tier).into());

let reserves = position
.data
.clone()
.expect("missing position metadata")
.reserves
.expect("missing position reserves");
let pair = position
.data
.expect("missing position")
.phi
.expect("missing position trading function")
.pair
.expect("missing trading function pair");
for position_id in position_ids {
// Fetch the information regarding the position from the view service.
let position = client
.liquidity_position_by_id(LiquidityPositionByIdRequest {
position_id: Some(PositionId::from(*position_id)),
})
.await?
.into_inner();

let plan = Planner::new(OsRng)
.set_gas_prices(gas_prices)
.set_fee_tier((*fee_tier).into())
.position_withdraw(*position_id, reserves.try_into()?, pair.try_into()?)
let reserves = position
.data
.clone()
.expect("missing position metadata")
.reserves
.expect("missing position reserves");
let pair = position
.data
.expect("missing position")
.phi
.expect("missing position trading function")
.pair
.expect("missing trading function pair");

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

let plan = planner
.plan(
app.view
.as_mut()
.context("view service must be initialized")?,
AddressIndex::new(*source),
)
.await?;

app.build_and_submit_transaction(plan).await?;
}
TxCmd::Position(PositionCmd::RewardClaim {}) => {
Expand Down
6 changes: 3 additions & 3 deletions crates/bin/pcli/src/command/tx/liquidity_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ pub enum PositionCmd {
#[clap(short, long, value_enum, default_value_t)]
fee_tier: FeeTier,
},
/// Debits a closed position NFT and credits a withdrawn position NFT and the final reserves.
/// Debits closed position NFTs and credits withdrawn position NFTs and the final reserves.
Withdraw {
/// Only spend funds originally received by the given address index.
#[clap(long, default_value = "0")]
source: u32,
/// The [`position::Id`] of the position to withdraw.
position_id: position::Id,
/// The list of [`position::Id`] of the positions to withdraw.
position_ids: Vec<position::Id>,
/// The selected fee tier to multiply the fee amount by.
#[clap(short, long, value_enum, default_value_t)]
fee_tier: FeeTier,
Expand Down

0 comments on commit b64e91c

Please sign in to comment.