use {
crate::{
error::TokenError,
extension::{Extension, ExtensionType},
},
bytemuck::{Pod, Zeroable},
trezoa_program_error::ProgramResult,
trezoa_zk_sdk::encryption::pod::elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
tpl_pod::{optional_keys::OptionalNonZeroPubkey, primitives::PodBool},
tpl_token_confidential_transfer_proof_extraction::encryption::PodFeeCiphertext,
};
pub mod instruction;
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())
}
}
}