pub use super::super::events;
use carbon_core::{borsh, deserialize::ArrangeAccounts};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Debug,
Clone,
carbon_core::borsh::BorshSerialize,
carbon_core::borsh::BorshDeserialize,
PartialEq,
)]
pub enum CpiEvent {
AddLiquidity(events::add_liquidity::AddLiquidityEvent),
RemoveLiquidity(events::remove_liquidity::RemoveLiquidityEvent),
StrategyDeposit(events::strategy_deposit::StrategyDepositEvent),
StrategyWithdraw(events::strategy_withdraw::StrategyWithdrawEvent),
ClaimReward(events::claim_reward::ClaimRewardEvent),
PerformanceFee(events::performance_fee::PerformanceFeeEvent),
ReportLoss(events::report_loss::ReportLossEvent),
TotalAmount(events::total_amount::TotalAmountEvent),
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CpiEventInstructionAccounts {
pub program: solana_pubkey::Pubkey,
pub event_authority: solana_pubkey::Pubkey,
pub remaining: Vec<solana_instruction::AccountMeta>,
}
impl CpiEvent {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [228, 69, 165, 46, 81, 203, 154, 29] {
return None;
}
let event_data = data;
if let Some(decoded) = events::add_liquidity::AddLiquidityEvent::decode(event_data) {
return Some(CpiEvent::AddLiquidity(decoded));
}
if let Some(decoded) = events::remove_liquidity::RemoveLiquidityEvent::decode(event_data) {
return Some(CpiEvent::RemoveLiquidity(decoded));
}
if let Some(decoded) = events::strategy_deposit::StrategyDepositEvent::decode(event_data) {
return Some(CpiEvent::StrategyDeposit(decoded));
}
if let Some(decoded) = events::strategy_withdraw::StrategyWithdrawEvent::decode(event_data)
{
return Some(CpiEvent::StrategyWithdraw(decoded));
}
if let Some(decoded) = events::claim_reward::ClaimRewardEvent::decode(event_data) {
return Some(CpiEvent::ClaimReward(decoded));
}
if let Some(decoded) = events::performance_fee::PerformanceFeeEvent::decode(event_data) {
return Some(CpiEvent::PerformanceFee(decoded));
}
if let Some(decoded) = events::report_loss::ReportLossEvent::decode(event_data) {
return Some(CpiEvent::ReportLoss(decoded));
}
if let Some(decoded) = events::total_amount::TotalAmountEvent::decode(event_data) {
return Some(CpiEvent::TotalAmount(decoded));
}
None
}
}
impl ArrangeAccounts for CpiEvent {
type ArrangedAccounts = CpiEventInstructionAccounts;
fn arrange_accounts(
accounts: &[solana_instruction::AccountMeta],
) -> Option<Self::ArrangedAccounts> {
match accounts {
[program, event_authority, remaining @ ..] => Some(CpiEventInstructionAccounts {
program: program.pubkey,
event_authority: event_authority.pubkey,
remaining: remaining.to_vec(),
}),
[event_authority] => Some(CpiEventInstructionAccounts {
program: crate::PROGRAM_ID,
event_authority: event_authority.pubkey,
remaining: Vec::new(),
}),
_ => None,
}
}
}