solana_zk_token_sdk/zk_token_elgamal/pod/
instruction.rs

1use crate::zk_token_elgamal::pod::{
2    GroupedElGamalCiphertext2Handles, GroupedElGamalCiphertext3Handles, PodU16, PodU64,
3};
4#[cfg(not(target_os = "solana"))]
5use crate::{errors::ElGamalError, instruction::transfer as decoded};
6
7#[derive(Clone, Copy, bytemuck_derive::Pod, bytemuck_derive::Zeroable)]
8#[repr(C)]
9pub struct TransferAmountCiphertext(pub GroupedElGamalCiphertext3Handles);
10
11#[cfg(not(target_os = "solana"))]
12impl From<decoded::TransferAmountCiphertext> for TransferAmountCiphertext {
13    fn from(decoded_ciphertext: decoded::TransferAmountCiphertext) -> Self {
14        Self(decoded_ciphertext.0.into())
15    }
16}
17
18#[cfg(not(target_os = "solana"))]
19impl TryFrom<TransferAmountCiphertext> for decoded::TransferAmountCiphertext {
20    type Error = ElGamalError;
21
22    fn try_from(pod_ciphertext: TransferAmountCiphertext) -> Result<Self, Self::Error> {
23        Ok(Self(pod_ciphertext.0.try_into()?))
24    }
25}
26
27#[derive(Clone, Copy, bytemuck_derive::Pod, bytemuck_derive::Zeroable)]
28#[repr(C)]
29pub struct FeeEncryption(pub GroupedElGamalCiphertext2Handles);
30
31#[cfg(not(target_os = "solana"))]
32impl From<decoded::FeeEncryption> for FeeEncryption {
33    fn from(decoded_ciphertext: decoded::FeeEncryption) -> Self {
34        Self(decoded_ciphertext.0.into())
35    }
36}
37
38#[cfg(not(target_os = "solana"))]
39impl TryFrom<FeeEncryption> for decoded::FeeEncryption {
40    type Error = ElGamalError;
41
42    fn try_from(pod_ciphertext: FeeEncryption) -> Result<Self, Self::Error> {
43        Ok(Self(pod_ciphertext.0.try_into()?))
44    }
45}
46
47#[derive(Clone, Copy, bytemuck_derive::Pod, bytemuck_derive::Zeroable)]
48#[repr(C)]
49pub struct FeeParameters {
50    /// Fee rate expressed as basis points of the transfer amount, i.e. increments of 0.01%
51    pub fee_rate_basis_points: PodU16,
52    /// Maximum fee assessed on transfers, expressed as an amount of tokens
53    pub maximum_fee: PodU64,
54}
55
56#[cfg(not(target_os = "solana"))]
57impl From<decoded::FeeParameters> for FeeParameters {
58    fn from(decoded_fee_parameters: decoded::FeeParameters) -> Self {
59        FeeParameters {
60            fee_rate_basis_points: decoded_fee_parameters.fee_rate_basis_points.into(),
61            maximum_fee: decoded_fee_parameters.maximum_fee.into(),
62        }
63    }
64}
65
66#[cfg(not(target_os = "solana"))]
67impl From<FeeParameters> for decoded::FeeParameters {
68    fn from(pod_fee_parameters: FeeParameters) -> Self {
69        decoded::FeeParameters {
70            fee_rate_basis_points: pod_fee_parameters.fee_rate_basis_points.into(),
71            maximum_fee: pod_fee_parameters.maximum_fee.into(),
72        }
73    }
74}