Skip to main content

carbon_orca_whirlpool_decoder/instructions/
decrease_liquidity.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Withdraw liquidity from a position in the Whirlpool. This call also updates
4/// the position's accrued fees and rewards. ### Authority
5/// - `position_authority` - authority that owns the token corresponding to this
6///   desired position.
7///
8/// ### Parameters
9/// - `liquidity_amount` - The total amount of Liquidity the user desires to
10///   withdraw.
11/// - `token_min_a` - The minimum amount of tokenA the user is willing to
12///   withdraw.
13/// - `token_min_b` - The minimum amount of tokenB the user is willing to
14///   withdraw.
15///
16/// #### Special Errors
17/// - `LiquidityZero` - Provided liquidity amount is zero.
18/// - `LiquidityTooHigh` - Provided liquidity exceeds u128::max.
19/// - `TokenMinSubceeded` - The required token to perform this operation
20///   subceeds the user defined amount.
21#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
22#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
23pub struct DecreaseLiquidity {
24    pub liquidity_amount: u128,
25    pub token_min_a: u64,
26    pub token_min_b: u64,
27}
28
29#[derive(Debug, Clone, PartialEq)]
30#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31pub struct DecreaseLiquidityInstructionAccounts {
32    pub whirlpool: solana_pubkey::Pubkey,
33    pub token_program: solana_pubkey::Pubkey,
34    pub position_authority: solana_pubkey::Pubkey,
35    pub position: solana_pubkey::Pubkey,
36    pub position_token_account: solana_pubkey::Pubkey,
37    pub token_owner_account_a: solana_pubkey::Pubkey,
38    pub token_owner_account_b: solana_pubkey::Pubkey,
39    pub token_vault_a: solana_pubkey::Pubkey,
40    pub token_vault_b: solana_pubkey::Pubkey,
41    pub tick_array_lower: solana_pubkey::Pubkey,
42    pub tick_array_upper: solana_pubkey::Pubkey,
43    pub remaining: Vec<solana_instruction::AccountMeta>,
44}
45
46impl DecreaseLiquidity {
47    pub fn decode(data: &[u8]) -> Option<Self> {
48        if data.len() < 8 {
49            return None;
50        }
51        let discriminator = &data[0..8];
52        if discriminator != [160, 38, 208, 111, 104, 91, 44, 1] {
53            return None;
54        }
55
56        let mut data_slice = data;
57
58        data_slice = &data_slice[8..];
59
60        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
61    }
62}
63
64impl ArrangeAccounts for DecreaseLiquidity {
65    type ArrangedAccounts = DecreaseLiquidityInstructionAccounts;
66
67    fn arrange_accounts(
68        accounts: &[solana_instruction::AccountMeta],
69    ) -> Option<Self::ArrangedAccounts> {
70        let mut iter = accounts.iter();
71
72        let whirlpool = next_account(&mut iter)?;
73        let token_program = next_account(&mut iter)?;
74        let position_authority = next_account(&mut iter)?;
75        let position = next_account(&mut iter)?;
76        let position_token_account = next_account(&mut iter)?;
77        let token_owner_account_a = next_account(&mut iter)?;
78        let token_owner_account_b = next_account(&mut iter)?;
79        let token_vault_a = next_account(&mut iter)?;
80        let token_vault_b = next_account(&mut iter)?;
81        let tick_array_lower = next_account(&mut iter)?;
82        let tick_array_upper = next_account(&mut iter)?;
83
84        let remaining = iter.as_slice();
85
86        Some(DecreaseLiquidityInstructionAccounts {
87            whirlpool,
88            token_program,
89            position_authority,
90            position,
91            position_token_account,
92            token_owner_account_a,
93            token_owner_account_b,
94            token_vault_a,
95            token_vault_b,
96            tick_array_lower,
97            tick_array_upper,
98            remaining: remaining.to_vec(),
99        })
100    }
101}