solana_clap_utils/
compute_budget.rs

1use {
2    crate::{input_validators::is_parsable, ArgConstant},
3    clap::Arg,
4};
5
6pub const COMPUTE_UNIT_PRICE_ARG: ArgConstant<'static> = ArgConstant {
7    name: "compute_unit_price",
8    long: "--with-compute-unit-price",
9    help: "Set compute unit price for transaction, in increments of 0.000001 lamports per compute \
10           unit.",
11};
12
13pub const COMPUTE_UNIT_LIMIT_ARG: ArgConstant<'static> = ArgConstant {
14    name: "compute_unit_limit",
15    long: "--with-compute-unit-limit",
16    help: "Set compute unit limit for transaction.",
17};
18
19pub fn compute_unit_price_arg<'a, 'b>() -> Arg<'a, 'b> {
20    Arg::with_name(COMPUTE_UNIT_PRICE_ARG.name)
21        .long(COMPUTE_UNIT_PRICE_ARG.long)
22        .takes_value(true)
23        .value_name("COMPUTE-UNIT-PRICE")
24        .validator(is_parsable::<u64>)
25        .help(COMPUTE_UNIT_PRICE_ARG.help)
26}
27
28pub fn compute_unit_limit_arg<'a, 'b>() -> Arg<'a, 'b> {
29    Arg::with_name(COMPUTE_UNIT_LIMIT_ARG.name)
30        .long(COMPUTE_UNIT_LIMIT_ARG.long)
31        .takes_value(true)
32        .value_name("COMPUTE-UNIT-LIMIT")
33        .validator(is_parsable::<u32>)
34        .help(COMPUTE_UNIT_LIMIT_ARG.help)
35}
36
37#[derive(Clone, Copy, Debug, PartialEq)]
38pub enum ComputeUnitLimit {
39    /// Do not include a compute unit limit instruction, which will give the
40    /// transaction a compute unit limit of:
41    /// `min(1_400_000, 200_000 * (num_top_level_instructions - num_compute_budget_instructions))`
42    Default,
43    /// Use a static predefined limit
44    Static(u32),
45    /// Simulate the transaction to find out the compute unit usage
46    Simulated,
47    /// Simulate the transaction and add a small percentage to account for potential drift
48    SimulatedWithExtraPercentage(u8),
49}