Skip to main content

soroban_cli/commands/tx/new/
liquidity_pool_withdraw.rs

1use clap::Parser;
2
3use crate::{commands::tx, tx::builder, xdr};
4
5#[derive(Parser, Debug, Clone)]
6#[group(skip)]
7pub struct Cmd {
8    #[command(flatten)]
9    pub tx: tx::Args,
10    #[clap(flatten)]
11    pub op: Args,
12}
13
14#[derive(Debug, clap::Args, Clone)]
15pub struct Args {
16    /// Liquidity pool ID to withdraw from
17    #[arg(long)]
18    pub liquidity_pool_id: String,
19
20    /// Amount of pool shares to withdraw, in stroops
21    #[arg(long)]
22    pub amount: builder::Amount,
23
24    /// Minimum amount of the first asset to receive, in stroops
25    #[arg(long)]
26    pub min_amount_a: builder::Amount,
27
28    /// Minimum amount of the second asset to receive, in stroops
29    #[arg(long)]
30    pub min_amount_b: builder::Amount,
31}
32
33impl TryFrom<&Cmd> for xdr::OperationBody {
34    type Error = tx::args::Error;
35    fn try_from(
36        Cmd {
37            tx: _,
38            op:
39                Args {
40                    liquidity_pool_id,
41                    amount,
42                    min_amount_a,
43                    min_amount_b,
44                },
45        }: &Cmd,
46    ) -> Result<Self, Self::Error> {
47        let pool_id: xdr::PoolId = liquidity_pool_id
48            .parse()
49            .map_err(|_| tx::args::Error::InvalidPoolId(liquidity_pool_id.clone()))?;
50
51        Ok(xdr::OperationBody::LiquidityPoolWithdraw(
52            xdr::LiquidityPoolWithdrawOp {
53                liquidity_pool_id: pool_id,
54                amount: amount.into(),
55                min_amount_a: min_amount_a.into(),
56                min_amount_b: min_amount_b.into(),
57            },
58        ))
59    }
60}