solana_program/sysvar/
fees.rs

1//! Current cluster fees.
2//!
3//! The _fees sysvar_ provides access to the [`Fees`] type, which contains the
4//! current [`FeeCalculator`].
5//!
6//! [`Fees`] implements [`Sysvar::get`] and can be loaded efficiently without
7//! passing the sysvar account ID to the program.
8//!
9//! This sysvar is deprecated and will not be available in the future.
10//! Transaction fees should be determined with the [`getFeeForMessage`] RPC
11//! method. For additional context see the [Comprehensive Compute Fees
12//! proposal][ccf].
13//!
14//! [`getFeeForMessage`]: https://solana.com/docs/rpc/http/getfeeformessage
15//! [ccf]: https://docs.solanalabs.com/proposals/comprehensive-compute-fees
16//!
17//! See also the Solana [documentation on the fees sysvar][sdoc].
18//!
19//! [sdoc]: https://docs.solanalabs.com/runtime/sysvars#fees
20
21#![allow(deprecated)]
22
23use {
24    crate::{
25        fee_calculator::FeeCalculator, impl_sysvar_get, program_error::ProgramError, sysvar::Sysvar,
26    },
27    solana_sdk_macro::CloneZeroed,
28    solana_sysvar_id::declare_deprecated_sysvar_id,
29};
30
31declare_deprecated_sysvar_id!("SysvarFees111111111111111111111111111111111", Fees);
32
33/// Transaction fees.
34#[deprecated(
35    since = "1.9.0",
36    note = "Please do not use, will no longer be available in the future"
37)]
38#[repr(C)]
39#[derive(Serialize, Deserialize, Debug, CloneZeroed, Default, PartialEq, Eq)]
40pub struct Fees {
41    pub fee_calculator: FeeCalculator,
42}
43
44impl Fees {
45    pub fn new(fee_calculator: &FeeCalculator) -> Self {
46        #[allow(deprecated)]
47        Self {
48            fee_calculator: *fee_calculator,
49        }
50    }
51}
52
53impl Sysvar for Fees {
54    impl_sysvar_get!(sol_get_fees_sysvar);
55}
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_clone() {
63        let fees = Fees {
64            fee_calculator: FeeCalculator {
65                lamports_per_signature: 1,
66            },
67        };
68        let cloned_fees = fees.clone();
69        assert_eq!(cloned_fees, fees);
70    }
71}