Skip to content

Commit

Permalink
Add priority fees (#472)
Browse files Browse the repository at this point in the history
* Add priority fees

* Use constant

* Can't use priority fee here as the transaction ends up too large

* Reduce max TX size to account for cpriority fees instruction

* Adds parameter to adjust priority fees

* remove compute unit budget where not required

---------

Co-authored-by: MarkSackerberg <[email protected]>
  • Loading branch information
blockchain-bros and MarkSackerberg authored Mar 15, 2024
1 parent 886c6f0 commit 4fb19e5
Show file tree
Hide file tree
Showing 22 changed files with 239 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/airdrop/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct AirdropArgs {
pub cache: String,
pub candy_machine: Option<String>,
pub airdrop_list: String,
pub priority_fee: u64,
}

pub async fn process_airdrop(args: AirdropArgs) -> Result<()> {
Expand Down Expand Up @@ -125,6 +126,7 @@ pub async fn process_airdrop(args: AirdropArgs) -> Result<()> {
candy_machine_state,
collection_update_authority,
target,
args.priority_fee,
)
.await;
pb.inc(1);
Expand Down
66 changes: 65 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
config::TokenStandard,
constants::{
DEFAULT_AIRDROP_LIST, DEFAULT_AIRDROP_LIST_HELP, DEFAULT_ASSETS, DEFAULT_CACHE,
DEFAULT_CONFIG,
DEFAULT_CONFIG, DEFAULT_PRIORITY_FEE,
},
};

Expand Down Expand Up @@ -61,6 +61,10 @@ pub enum Commands {
#[clap(short, long)]
rpc_url: Option<String>,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Path to the cache file, defaults to "cache.json"
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,
Expand Down Expand Up @@ -115,6 +119,10 @@ pub enum Commands {
#[clap(short, long)]
rpc_url: Option<String>,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Path to the cache file
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,
Expand Down Expand Up @@ -142,6 +150,10 @@ pub enum Commands {
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Amount of NFTs to be minted in bulk
#[clap(short, long)]
number: Option<u64>,
Expand All @@ -168,6 +180,10 @@ pub enum Commands {
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Address of candy machine to mint from.
#[clap(long)]
candy_machine: Option<String>,
Expand Down Expand Up @@ -259,6 +275,10 @@ pub enum Commands {
#[clap(short, long)]
keypair: Option<String>,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// RPC Url
#[clap(short, long)]
rpc_url: Option<String>,
Expand Down Expand Up @@ -312,6 +332,10 @@ pub enum Commands {
#[clap(short, long)]
rpc_url: Option<String>,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// List available candy machines, no withdraw performed
#[clap(long)]
list: bool,
Expand Down Expand Up @@ -366,6 +390,10 @@ pub enum ConfigSubcommands {
#[clap(short, long)]
rpc_url: Option<String>,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Path to the cache file, defaults to "cache.json"
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,
Expand All @@ -392,6 +420,10 @@ pub enum ConfigSubcommands {
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Token Standard to set.
#[clap(short, long)]
token_standard: Option<TokenStandard>,
Expand Down Expand Up @@ -422,6 +454,10 @@ pub enum CollectionSubcommands {
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Path to the config file
#[clap(short, long, default_value = DEFAULT_CONFIG)]
config: String,
Expand Down Expand Up @@ -455,6 +491,10 @@ pub enum GuardCommand {
#[clap(short, long, default_value = DEFAULT_CONFIG)]
config: String,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Address of the candy machine.
#[clap(long)]
candy_machine: Option<String>,
Expand All @@ -477,6 +517,10 @@ pub enum GuardCommand {
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Address of the candy machine.
#[clap(long)]
candy_machine: Option<String>,
Expand Down Expand Up @@ -517,6 +561,10 @@ pub enum GuardCommand {
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Path to the config file
#[clap(short, long, default_value = DEFAULT_CONFIG)]
config: String,
Expand All @@ -535,6 +583,10 @@ pub enum GuardCommand {
#[clap(short, long)]
rpc_url: Option<String>,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Path to the cache file, defaults to "cache.json"
#[clap(long, default_value = DEFAULT_CACHE)]
cache: String,
Expand Down Expand Up @@ -573,6 +625,10 @@ pub enum FreezeCommand {
#[clap(long)]
candy_machine: Option<String>,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Candy guard group label.
#[clap(long)]
label: Option<String>,
Expand Down Expand Up @@ -610,6 +666,10 @@ pub enum FreezeCommand {
#[clap(long)]
candy_guard: Option<String>,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Address of candy machine to update [defaults to cache value].
#[clap(long)]
candy_machine: Option<String>,
Expand Down Expand Up @@ -652,6 +712,10 @@ pub enum FreezeCommand {
#[clap(short, long, default_value = DEFAULT_CONFIG)]
config: String,

/// Priority fee value
#[clap(short, long, default_value_t = DEFAULT_PRIORITY_FEE)]
priority_fee: u64,

/// Address of candy guard to update [defaults to cache value].
#[clap(long)]
candy_guard: Option<String>,
Expand Down
11 changes: 10 additions & 1 deletion src/collections/set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{ops::Deref, str::FromStr};

use anchor_client::solana_sdk::{pubkey::Pubkey, system_program};
use anchor_client::solana_sdk::{
compute_budget::ComputeBudgetInstruction, pubkey::Pubkey, system_program,
};
use anyhow::Result;
use console::style;
use mpl_candy_machine_core::{
Expand Down Expand Up @@ -31,6 +33,7 @@ pub struct SetCollectionArgs {
pub cache: String,
pub config: String,
pub candy_machine: Option<String>,
pub priority_fee: u64,
}

pub fn process_set_collection(args: SetCollectionArgs) -> Result<()> {
Expand Down Expand Up @@ -109,6 +112,7 @@ pub fn process_set_collection(args: SetCollectionArgs) -> Result<()> {
&collection_mint_pubkey,
&collection_metadata_info,
&collection_edition_info,
&args,
)?;

pb.finish_with_message(format!(
Expand Down Expand Up @@ -146,6 +150,7 @@ pub fn process_set_collection(args: SetCollectionArgs) -> Result<()> {
new_authority: None,
config: args.config,
candy_machine: Some(candy_machine_id),
priority_fee: args.priority_fee,
};

process_update(update_args)?;
Expand All @@ -162,6 +167,7 @@ pub fn set_collection<C: Deref<Target = impl Signer> + Clone>(
new_collection_mint_pubkey: &Pubkey,
new_collection_metadata_info: &PdaInfo<Metadata>,
new_collection_edition_info: &PdaInfo<MasterEditionV2>,
args: &SetCollectionArgs,
) -> Result<Signature> {
let payer = program.payer();

Expand Down Expand Up @@ -214,8 +220,11 @@ pub fn set_collection<C: Deref<Target = impl Signer> + Clone>(
let collection_update_authority = collection_metadata.update_authority;
let collection_metadata = find_metadata_pda(&collection_mint);

let priority_fee = ComputeBudgetInstruction::set_compute_unit_price(args.priority_fee);

let builder = program
.request()
.instruction(priority_fee)
.accounts(nft_accounts::SetCollectionV2 {
candy_machine: *candy_pubkey,
authority: payer,
Expand Down
2 changes: 2 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ pub const UNWRAP_EMOJI: Emoji<'_, '_> = Emoji("🔩 ", "");
pub const MAX_FREEZE_DAYS: u8 = 31;

pub const COMPUTE_UNITS: u32 = 400_000;

pub const DEFAULT_PRIORITY_FEE: u64 = 500;
6 changes: 5 additions & 1 deletion src/deploy/collection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anchor_client::solana_sdk::pubkey::Pubkey;
use anchor_client::solana_sdk::{compute_budget::ComputeBudgetInstruction, pubkey::Pubkey};
use anyhow::Result;
use mpl_token_metadata::{
instruction::{create_master_edition_v3, create_metadata_accounts_v3},
Expand All @@ -16,6 +16,7 @@ use crate::{
candy_machine::CANDY_MACHINE_ID,
common::*,
config::ConfigData,
deploy::DeployArgs,
pdas::{find_master_edition_pda, find_metadata_pda},
setup::SugarClient,
};
Expand All @@ -25,6 +26,7 @@ pub fn create_collection(
_candy_machine: Pubkey,
cache: &mut Cache,
config_data: &ConfigData,
args: &DeployArgs,
) -> Result<(Signature, Pubkey)> {
let program = client.program(CANDY_MACHINE_ID);
let payer = program.payer();
Expand Down Expand Up @@ -114,9 +116,11 @@ pub fn create_collection(
payer,
Some(0),
);
let priority_fee = ComputeBudgetInstruction::set_compute_unit_price(args.priority_fee);

let builder = program
.request()
.instruction(priority_fee)
.instruction(create_mint_account_ix)
.instruction(init_mint_ix)
.instruction(create_assoc_account_ix)
Expand Down
29 changes: 20 additions & 9 deletions src/deploy/config_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::{
},
};

use anchor_client::solana_sdk::{pubkey::Pubkey, signature::Keypair};
use anchor_client::solana_sdk::{
compute_budget::ComputeBudgetInstruction, pubkey::Pubkey, signature::Keypair,
};
use anyhow::Result;
use console::style;
use futures::future::select_all;
Expand All @@ -23,7 +25,7 @@ use crate::{
};

/// The maximum config line bytes per transaction.
const MAX_TRANSACTION_BYTES: usize = 1000;
const MAX_TRANSACTION_BYTES: usize = 966;

/// The maximum number of config lines per transaction.
const MAX_TRANSACTION_LINES: usize = 17;
Expand Down Expand Up @@ -106,6 +108,7 @@ pub async fn upload_config_lines(
cache: &mut Cache,
config_lines: Vec<Vec<(u32, ConfigLine)>>,
interrupted: Arc<AtomicBool>,
priority_fee: u64,
) -> Result<Vec<DeployError>> {
println!(
"Sending config line(s) in {} transaction(s): (Ctrl+C to abort)",
Expand Down Expand Up @@ -134,9 +137,9 @@ pub async fn upload_config_lines(

for tx in transactions.drain(0..cmp::min(transactions.len(), PARALLEL_LIMIT)) {
let config = sugar_config.clone();
handles.push(tokio::spawn(
async move { add_config_lines(config, tx).await },
));
handles.push(tokio::spawn(async move {
add_config_lines(config, tx, priority_fee).await
}));
}

let mut errors = Vec::new();
Expand Down Expand Up @@ -184,9 +187,9 @@ pub async fn upload_config_lines(

for tx in transactions.drain(0..cmp::min(transactions.len(), PARALLEL_LIMIT / 2)) {
let config = sugar_config.clone();
handles.push(tokio::spawn(
async move { add_config_lines(config, tx).await },
));
handles.push(tokio::spawn(async move {
add_config_lines(config, tx, priority_fee).await
}));
}
}
}
Expand Down Expand Up @@ -214,12 +217,17 @@ pub async fn upload_config_lines(
}

/// Send the `add_config_lines` instruction to the candy machine program.
pub async fn add_config_lines(config: Arc<SugarConfig>, tx_info: TxInfo) -> Result<Vec<u32>> {
pub async fn add_config_lines(
config: Arc<SugarConfig>,
tx_info: TxInfo,
priority_fee: u64,
) -> Result<Vec<u32>> {
let client = setup_client(&config)?;
let program = client.program(CANDY_MACHINE_ID);

// this will be used to update the cache
let mut indices: Vec<u32> = Vec::new();

// configLine does not implement clone, so we have to do this
let mut config_lines: Vec<ConfigLine> = Vec::new();
// start index
Expand All @@ -230,8 +238,11 @@ pub async fn add_config_lines(config: Arc<SugarConfig>, tx_info: TxInfo) -> Resu
config_lines.push(line);
}

let priority_fee = ComputeBudgetInstruction::set_compute_unit_price(priority_fee);

let _sig = program
.request()
.instruction(priority_fee)
.accounts(nft_accounts::AddConfigLines {
candy_machine: tx_info.candy_pubkey,
authority: program.payer(),
Expand Down
Loading

0 comments on commit 4fb19e5

Please sign in to comment.