1use crate::native_token::cbc_to_scoobies;
4
5#[derive(Debug, Default, Clone, Eq, PartialEq)]
7pub struct FeeBin {
8 pub limit: u64,
10 pub fee: u64,
12}
13
14#[derive(Debug, Clone, Eq, PartialEq)]
16pub struct FeeStructure {
17 pub scoobies_per_signature: u64,
19 pub scoobies_per_write_lock: u64,
21 pub compute_fee_bins: Vec<FeeBin>,
23}
24
25impl FeeStructure {
26 pub fn new(
27 cbe_per_signature: f64,
28 cbe_per_write_lock: f64,
29 compute_fee_bins: Vec<(u64, f64)>,
30 ) -> Self {
31 let compute_fee_bins = compute_fee_bins
32 .iter()
33 .map(|(limit, cbc)| FeeBin {
34 limit: *limit,
35 fee: cbc_to_scoobies(*cbc),
36 })
37 .collect::<Vec<_>>();
38 FeeStructure {
39 scoobies_per_signature: cbc_to_scoobies(cbe_per_signature),
40 scoobies_per_write_lock: cbc_to_scoobies(cbe_per_write_lock),
41 compute_fee_bins,
42 }
43 }
44
45 pub fn get_max_fee(&self, num_signatures: u64, num_write_locks: u64) -> u64 {
46 num_signatures
47 .saturating_mul(self.scoobies_per_signature)
48 .saturating_add(num_write_locks.saturating_mul(self.scoobies_per_write_lock))
49 .saturating_add(
50 self.compute_fee_bins
51 .last()
52 .map(|bin| bin.fee)
53 .unwrap_or_default(),
54 )
55 }
56}
57
58impl Default for FeeStructure {
59 fn default() -> Self {
60 Self::new(0.000005, 0.0, vec![(1_400_000, 0.0)])
61 }
62}
63
64#[cfg(RUSTC_WITH_SPECIALIZATION)]
65impl ::cbe_frozen_abi::abi_example::AbiExample for FeeStructure {
66 fn example() -> Self {
67 FeeStructure::default()
68 }
69}