use {
crate::{
error::TokenError,
extension::{Extension, ExtensionType},
},
bytemuck::{Pod, Zeroable},
solana_program::entrypoint::ProgramResult,
solana_zk_sdk::encryption::pod::elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
spl_pod::{optional_keys::OptionalNonZeroPubkey, primitives::PodBool},
gorb_ct_proof_extraction::encryption::PodFeeCiphertext,
};
pub mod instruction;
pub mod processor;
#[cfg(not(target_os = "solana"))]
pub mod account_info;
pub type EncryptedFee = PodFeeCiphertext;
pub type EncryptedWithheldAmount = PodElGamalCiphertext;
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
pub struct ConfidentialTransferFeeConfig {
pub authority: OptionalNonZeroPubkey,
pub withdraw_withheld_authority_elgamal_pubkey: PodElGamalPubkey,
pub harvest_to_mint_enabled: PodBool,
pub withheld_amount: EncryptedWithheldAmount,
}
impl Extension for ConfidentialTransferFeeConfig {
const TYPE: ExtensionType = ExtensionType::ConfidentialTransferFeeConfig;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
pub struct ConfidentialTransferFeeAmount {
pub withheld_amount: EncryptedWithheldAmount,
}
impl Extension for ConfidentialTransferFeeAmount {
const TYPE: ExtensionType = ExtensionType::ConfidentialTransferFeeAmount;
}
impl ConfidentialTransferFeeAmount {
pub fn closable(&self) -> ProgramResult {
if self.withheld_amount == EncryptedWithheldAmount::zeroed() {
Ok(())
} else {
Err(TokenError::ConfidentialTransferFeeAccountHasWithheldFee.into())
}
}
}