use solana_sdk::{pubkey::Pubkey, signature::Signature};
use super::CurrencyAmount;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IncreaseLiquidityParam {
TokenA(u64),
TokenB(u64),
TokenAAndB(u64, u64),
Liquidity(u128),
}
impl IncreaseLiquidityParam {
pub fn token_a(amount: u64) -> Self {
Self::TokenA(amount)
}
pub fn token_b(amount: u64) -> Self {
Self::TokenB(amount)
}
pub fn token_a_and_b(amount_a: u64, amount_b: u64) -> Self {
Self::TokenAAndB(amount_a, amount_b)
}
pub fn liquidity(amount: u128) -> Self {
Self::Liquidity(amount)
}
pub fn token_a_amount(&self) -> Option<u64> {
match self {
Self::TokenA(amount) => Some(*amount),
Self::TokenAAndB(amount_a, _) => Some(*amount_a),
_ => None,
}
}
pub fn token_b_amount(&self) -> Option<u64> {
match self {
Self::TokenB(amount) => Some(*amount),
Self::TokenAAndB(_, amount_b) => Some(*amount_b),
_ => None,
}
}
pub fn token_amounts(&self) -> Option<(u64, u64)> {
match self {
Self::TokenAAndB(amount_a, amount_b) => Some((*amount_a, *amount_b)),
_ => None,
}
}
pub fn liquidity_amount(&self) -> Option<u128> {
match self {
Self::Liquidity(amount) => Some(*amount),
_ => None,
}
}
pub fn is_token_a(&self) -> bool {
matches!(self, Self::TokenA(_))
}
pub fn is_token_b(&self) -> bool {
matches!(self, Self::TokenB(_))
}
pub fn is_token_a_and_b(&self) -> bool {
matches!(self, Self::TokenAAndB(_, _))
}
pub fn is_liquidity(&self) -> bool {
matches!(self, Self::Liquidity(_))
}
}
#[derive(Clone, Debug)]
pub struct AddLiquidityResult {
pub position_address: Pubkey,
pub liquidity: u128,
pub amount_a: CurrencyAmount,
pub amount_b: CurrencyAmount,
pub tick_upper: i32,
pub tick_lower: i32,
pub signature: Signature,
}
#[derive(Clone, Debug)]
pub struct AddLiquidityResultItem {
pub position_address: Pubkey,
pub liquidity: u128,
pub amount_a: CurrencyAmount,
pub amount_b: CurrencyAmount,
pub tick_upper: i32,
pub tick_lower: i32,
}
#[derive(Clone, Debug)]
pub struct AddBatchLiquidityResult {
pub results: Vec<AddLiquidityResultItem>,
pub signature: Signature,
}
#[derive(Clone, Debug)]
pub struct RemoveLiquidityResult {
pub position_address: Pubkey,
pub liquidity: u128,
pub amount_a: CurrencyAmount,
pub amount_b: CurrencyAmount,
pub amount_a_from_liquidity: CurrencyAmount,
pub amount_b_from_liquidity: CurrencyAmount,
pub recipient: Pubkey,
pub signature: Signature,
}
#[derive(Clone, Debug)]
pub struct RemoveLiquidityResultItem {
pub position_address: Pubkey,
pub liquidity: u128,
pub amount_a: CurrencyAmount,
pub amount_b: CurrencyAmount,
pub amount_a_from_liquidity: CurrencyAmount,
pub amount_b_from_liquidity: CurrencyAmount,
pub recipient: Pubkey,
}
#[derive(Clone, Debug)]
pub struct RemoveBatchLiquidityResult {
pub results: Vec<RemoveLiquidityResultItem>,
pub signature: Signature,
}
#[derive(Clone, Debug)]
pub struct CollectResult {
pub position_address: Pubkey,
pub amount_a: CurrencyAmount,
pub amount_b: CurrencyAmount,
pub recipient: Pubkey,
pub signature: Signature,
}
#[cfg(feature = "rpc")]
#[derive(Clone, Debug)]
pub struct SimulateAddLiquidityResult {
pub simulation: solana_client::rpc_response::RpcSimulateTransactionResult,
pub liquidity_increased_event: Option<LiquidityIncreasedEvent>,
pub quote: Option<AddLiquidityQuoteData>,
}
#[derive(Clone, Debug)]
pub struct LiquidityIncreasedEvent {
pub position: Pubkey,
pub liquidity: u128,
pub token_a_amount: u64,
pub token_b_amount: u64,
pub tick_lower_index: i32,
pub tick_upper_index: i32,
}
#[derive(Clone, Debug)]
pub struct AddLiquidityQuoteData {
pub liquidity_delta: u128,
pub token_est_a: u64,
pub token_est_b: u64,
}
#[cfg(feature = "rpc")]
#[derive(Clone, Debug)]
pub struct SimulateRemoveLiquidityResult {
pub simulation: solana_client::rpc_response::RpcSimulateTransactionResult,
pub liquidity_decreased_event: Option<LiquidityDecreasedEvent>,
pub quote: Option<RemoveLiquidityQuoteData>,
}
#[derive(Clone, Debug)]
pub struct LiquidityDecreasedEvent {
pub position: Pubkey,
pub liquidity: u128,
pub token_a_amount: u64,
pub token_b_amount: u64,
pub tick_lower_index: i32,
pub tick_upper_index: i32,
}
#[derive(Clone, Debug)]
pub struct RemoveLiquidityQuoteData {
pub liquidity_delta: i128,
pub token_min_a: u64,
pub token_min_b: u64,
pub fees_quote: CollectFeesQuoteData,
}
#[derive(Clone, Debug)]
pub struct CollectFeesQuoteData {
pub fee_owed_a: u64,
pub fee_owed_b: u64,
}
#[cfg(feature = "rpc")]
#[derive(Clone, Debug)]
pub struct SimulateCollectResult {
pub simulation: solana_client::rpc_response::RpcSimulateTransactionResult,
pub fees_quote: CollectFeesQuoteData,
}