Skip to main content

carbon_orca_whirlpool_decoder/instructions/
decrease_liquidity_v2.rs

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