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 unit.",
10};
11
12pub const COMPUTE_UNIT_LIMIT_ARG: ArgConstant<'static> = ArgConstant {
13    name: "compute_unit_limit",
14    long: "--with-compute-unit-limit",
15    help: "Set compute unit limit for transaction.",
16};
17
18pub fn compute_unit_price_arg<'a, 'b>() -> Arg<'a, 'b> {
19    Arg::with_name(COMPUTE_UNIT_PRICE_ARG.name)
20        .long(COMPUTE_UNIT_PRICE_ARG.long)
21        .takes_value(true)
22        .value_name("COMPUTE-UNIT-PRICE")
23        .validator(is_parsable::<u64>)
24        .help(COMPUTE_UNIT_PRICE_ARG.help)
25}
26
27pub fn compute_unit_limit_arg<'a, 'b>() -> Arg<'a, 'b> {
28    Arg::with_name(COMPUTE_UNIT_LIMIT_ARG.name)
29        .long(COMPUTE_UNIT_LIMIT_ARG.long)
30        .takes_value(true)
31        .value_name("COMPUTE-UNIT-LIMIT")
32        .validator(is_parsable::<u32>)
33        .help(COMPUTE_UNIT_LIMIT_ARG.help)
34}
35
36#[derive(Clone, Copy, Debug, PartialEq)]
37pub enum ComputeUnitLimit {
38    /// Do not include a compute unit limit instruction, which will give the
39    /// transaction a compute unit limit of:
40    /// `min(1_400_000, 200_000 * (num_top_level_instructions - num_compute_budget_instructions))`
41    Default,
42    /// Use a static predefined limit
43    Static(u32),
44    /// Simulate the transaction to find out the compute unit usage
45    Simulated,
46}