2021-07-16 00:31:22 -07:00
|
|
|
#![cfg(feature = "full")]
|
|
|
|
|
2021-08-17 15:17:56 -07:00
|
|
|
use {
|
2022-01-17 04:48:00 -08:00
|
|
|
crate::instruction::Instruction,
|
2022-02-11 16:23:16 -08:00
|
|
|
borsh::{BorshDeserialize, BorshSerialize},
|
2021-07-16 00:31:22 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
crate::declare_id!("ComputeBudget111111111111111111111111111111");
|
|
|
|
|
|
|
|
/// Compute Budget Instructions
|
|
|
|
#[derive(
|
2022-02-11 16:23:16 -08:00
|
|
|
AbiExample,
|
|
|
|
AbiEnumVisitor,
|
2021-07-16 00:31:22 -07:00
|
|
|
BorshDeserialize,
|
2022-02-11 16:23:16 -08:00
|
|
|
BorshSerialize,
|
2021-07-16 00:31:22 -07:00
|
|
|
Clone,
|
2022-02-11 16:23:16 -08:00
|
|
|
Debug,
|
|
|
|
Deserialize,
|
2021-07-16 00:31:22 -07:00
|
|
|
PartialEq,
|
2022-05-22 18:00:42 -07:00
|
|
|
Eq,
|
2022-02-11 16:23:16 -08:00
|
|
|
Serialize,
|
2021-07-16 00:31:22 -07:00
|
|
|
)]
|
|
|
|
pub enum ComputeBudgetInstruction {
|
2022-05-12 11:07:36 -07:00
|
|
|
/// Deprecated
|
|
|
|
RequestUnitsDeprecated {
|
2022-02-11 16:23:16 -08:00
|
|
|
/// Units to request
|
|
|
|
units: u32,
|
|
|
|
/// Additional fee to add
|
|
|
|
additional_fee: u32,
|
|
|
|
},
|
|
|
|
/// Request a specific transaction-wide program heap region size in bytes.
|
|
|
|
/// The value requested must be a multiple of 1024. This new heap region
|
2022-05-12 11:07:36 -07:00
|
|
|
/// size applies to each program executed in the transaction, including all
|
|
|
|
/// calls to CPIs.
|
2021-10-19 21:01:39 -07:00
|
|
|
RequestHeapFrame(u32),
|
2022-05-17 22:14:31 -07:00
|
|
|
/// Set a specific compute unit limit that the transaction is allowed to consume.
|
|
|
|
SetComputeUnitLimit(u32),
|
2022-05-15 21:06:33 -07:00
|
|
|
/// Set a compute unit price in "micro-lamports" to pay a higher transaction
|
|
|
|
/// fee for higher transaction prioritization.
|
|
|
|
SetComputeUnitPrice(u64),
|
2021-07-16 00:31:22 -07:00
|
|
|
}
|
2022-01-17 04:48:00 -08:00
|
|
|
|
2021-07-22 10:18:51 -07:00
|
|
|
impl ComputeBudgetInstruction {
|
2022-05-12 11:07:36 -07:00
|
|
|
/// Create a `ComputeBudgetInstruction::RequestHeapFrame` `Instruction`
|
|
|
|
pub fn request_heap_frame(bytes: u32) -> Instruction {
|
|
|
|
Instruction::new_with_borsh(id(), &Self::RequestHeapFrame(bytes), vec![])
|
|
|
|
}
|
|
|
|
|
2022-05-17 22:14:31 -07:00
|
|
|
/// Create a `ComputeBudgetInstruction::SetComputeUnitLimit` `Instruction`
|
|
|
|
pub fn set_compute_unit_limit(units: u32) -> Instruction {
|
|
|
|
Instruction::new_with_borsh(id(), &Self::SetComputeUnitLimit(units), vec![])
|
2021-07-22 10:18:51 -07:00
|
|
|
}
|
2022-01-17 04:48:00 -08:00
|
|
|
|
2022-05-15 21:06:33 -07:00
|
|
|
/// Create a `ComputeBudgetInstruction::SetComputeUnitPrice` `Instruction`
|
|
|
|
pub fn set_compute_unit_price(micro_lamports: u64) -> Instruction {
|
|
|
|
Instruction::new_with_borsh(id(), &Self::SetComputeUnitPrice(micro_lamports), vec![])
|
2021-10-19 21:01:39 -07:00
|
|
|
}
|
2021-07-16 00:31:22 -07:00
|
|
|
}
|