Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add priority fees to create #332

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ indicatif = { version = "0.16.2", features = ["rayon"] }
jib = "0.8.0"
lazy_static = "1.4.0"
log = "0.4.20"
metaboss_lib = "0.18.0"
metaboss_lib = "0.19.0"
mpl-token-metadata = { version = "3.2.3", features = ["serde"] }
num_cpus = "1.16.0"
once_cell = "1.19.0"
Expand Down
31 changes: 0 additions & 31 deletions docs-src/src/priority-fees.md
Original file line number Diff line number Diff line change
@@ -1,32 +1 @@
# Priority Fees

To specify priority fees on Metaboss transactions, use the `--priority/-p` flag. The current priority values are set at:


| Priority | MicroLamport Units |
|------------|--------------------|
| "none" | 20 |
| "low" | 20_000 |
| "medium" | 200_000 |
| "high" | 1_000_000 |
| "max" | 2_000_000 |
|------------|--------------------|

The default value if no priority is specified is `None`.

The total amount spennt on priority fees per transaction is the microlamports multiplied by the compute units used. The approximate value of each priority level for the `update` subcommands are given below with a hard-coded compute unit value of 50k:

| Priority | MicroLamport Units | Approximate Value @ $150 |
|------------|-----------|-----------------------------------|
| "none" | 20 | 1 lamport/update |
| "low" | 20_000 | ~$1 for 10k updates |
| "medium" | 200_000 | ~$10 for 10k updates |
| "high" | 1_000_000 | ~$0.01/update @ $150 SOL |
| "max" | 2_000_000 | ~$0.02/update @ $150 SOL |
|------------|-----------|-----------------------------------|

Currently only `update` subcommands support priority fees.

**When running large batch updates be sure to consider the cost of priority fees for the level you set!!**


23 changes: 23 additions & 0 deletions docs-src/src/priority_fees.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Priority Fees

To specify priority fees on Metaboss transactions, use the `--priority/-p` flag. The current priority values are set at:


| Priority | MicroLamport Units |
|------------|--------------------|
| "none" | 20 |
| "low" | 20_000 |
| "medium" | 200_000 |
| "high" | 1_000_000 |
| "max" | 2_000_000 |
|------------|--------------------|

The default value if no priority is specified is `None`.

The total amount spennt on priority fees per transaction is the microlamports multiplied by the compute units used. Metaboss simulates each tranasaction to determine the compute units required, and then uses that value or a default.

Setting higher levels of priority fees are unlikely to make a significant difference in the getting transactions confirmed, so it's recommended to use "none" or "low" until Solana network performance improves. However, higher levels are included to give users options.

**When running large batch updates be sure to consider the cost of priority fees for the level you set!! Medium, High and Max could cost significant amounts of SOL when updating thousands of NFTs.**


23 changes: 0 additions & 23 deletions docs/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -1480,29 +1480,6 @@ <h4 id="usage-48"><a class="header" href="#usage-48">Usage</a></h4>
<div style="break-before: page; page-break-before: always;"></div><h2 id="withdraw-deprecated"><a class="header" href="#withdraw-deprecated">Withdraw (Deprecated)</a></h2>
<p>Use Metaplex's <a href="https://docs.metaplex.com/sugar/introduction">Sugar</a> tool for withdrawing from candy machines instead.</p>
<div style="break-before: page; page-break-before: always;"></div><h1 id="priority-fees"><a class="header" href="#priority-fees">Priority Fees</a></h1>
<p>To specify priority fees on Metaboss transactions, use the <code>--priority/-p</code> flag. The current priority values are set at:</p>
<div class="table-wrapper"><table><thead><tr><th>Priority</th><th>MicroLamport Units</th></tr></thead><tbody>
<tr><td>"none"</td><td>20</td></tr>
<tr><td>"low"</td><td>20_000</td></tr>
<tr><td>"medium"</td><td>200_000</td></tr>
<tr><td>"high"</td><td>1_000_000</td></tr>
<tr><td>"max"</td><td>2_000_000</td></tr>
<tr><td>------------</td><td>--------------------</td></tr>
</tbody></table>
</div>
<p>The default value if no priority is specified is <code>None</code>.</p>
<p>The total amount spennt on priority fees per transaction is the microlamports multiplied by the compute units used. The approximate value of each priority level for the <code>update</code> subcommands are given below with a hard-coded compute unit value of 50k:</p>
<div class="table-wrapper"><table><thead><tr><th>Priority</th><th>MicroLamport Units</th><th>Approximate Value @ $150</th></tr></thead><tbody>
<tr><td>"none"</td><td>20</td><td>1 lamport/update</td></tr>
<tr><td>"low"</td><td>20_000</td><td>~$1 for 10k updates</td></tr>
<tr><td>"medium"</td><td>200_000</td><td>~$10 for 10k updates</td></tr>
<tr><td>"high"</td><td>1_000_000</td><td>~$0.01/update @ $150 SOL</td></tr>
<tr><td>"max"</td><td>2_000_000</td><td>~$0.02/update @ $150 SOL</td></tr>
<tr><td>------------</td><td>-----------</td><td>-----------------------------------</td></tr>
</tbody></table>
</div>
<p>Currently only <code>update</code> subcommands support priority fees.</p>
<p><strong>When running large batch updates be sure to consider the cost of priority fees for the level you set!!</strong></p>
<div style="break-before: page; page-break-before: always;"></div><h2 id="contact"><a class="header" href="#contact">Contact</a></h2>
<p>Email: sam@vanderwaal.dev</p>
<p>Twitter: <a href="https://twitter.com/samvwaal">@samvwaal</a></p>
Expand Down
23 changes: 0 additions & 23 deletions docs/priority-fees.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,29 +174,6 @@ <h1 class="menu-title">Metaboss</h1>
<div id="content" class="content">
<main>
<h1 id="priority-fees"><a class="header" href="#priority-fees">Priority Fees</a></h1>
<p>To specify priority fees on Metaboss transactions, use the <code>--priority/-p</code> flag. The current priority values are set at:</p>
<div class="table-wrapper"><table><thead><tr><th>Priority</th><th>MicroLamport Units</th></tr></thead><tbody>
<tr><td>"none"</td><td>20</td></tr>
<tr><td>"low"</td><td>20_000</td></tr>
<tr><td>"medium"</td><td>200_000</td></tr>
<tr><td>"high"</td><td>1_000_000</td></tr>
<tr><td>"max"</td><td>2_000_000</td></tr>
<tr><td>------------</td><td>--------------------</td></tr>
</tbody></table>
</div>
<p>The default value if no priority is specified is <code>None</code>.</p>
<p>The total amount spennt on priority fees per transaction is the microlamports multiplied by the compute units used. The approximate value of each priority level for the <code>update</code> subcommands are given below with a hard-coded compute unit value of 50k:</p>
<div class="table-wrapper"><table><thead><tr><th>Priority</th><th>MicroLamport Units</th><th>Approximate Value @ $150</th></tr></thead><tbody>
<tr><td>"none"</td><td>20</td><td>1 lamport/update</td></tr>
<tr><td>"low"</td><td>20_000</td><td>~$1 for 10k updates</td></tr>
<tr><td>"medium"</td><td>200_000</td><td>~$10 for 10k updates</td></tr>
<tr><td>"high"</td><td>1_000_000</td><td>~$0.01/update @ $150 SOL</td></tr>
<tr><td>"max"</td><td>2_000_000</td><td>~$0.02/update @ $150 SOL</td></tr>
<tr><td>------------</td><td>-----------</td><td>-----------------------------------</td></tr>
</tbody></table>
</div>
<p>Currently only <code>update</code> subcommands support priority fees.</p>
<p><strong>When running large batch updates be sure to consider the cost of priority fees for the level you set!!</strong></p>

</main>

Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

85 changes: 76 additions & 9 deletions src/create/methods.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
use std::path::PathBuf;

use anyhow::anyhow;
use metaboss_lib::{derive::derive_edition_pda, transaction::send_and_confirm_tx};
use metaboss_lib::{
data::Priority,
derive::derive_edition_pda,
transaction::{get_compute_units, send_and_confirm_tx},
};
use mpl_token_metadata::{
instructions::{CreateBuilder, CreateMasterEditionV3Builder},
types::{CreateArgs, DataV2, TokenStandard},
};
use solana_sdk::signature::read_keypair_file;
use solana_sdk::{compute_budget::ComputeBudgetInstruction, signature::read_keypair_file};
use spl_associated_token_account::get_associated_token_address;
use spl_token::instruction::mint_to;

use crate::utils::create_token_if_missing_instruction;

use super::*;

// Arbitrary and capricious. Only used in the tx simulation does not return a value.
const DEFAULT_COMPUTE_UNITS: u64 = 75_000;

pub struct CreateMetadataArgs {
pub client: RpcClient,
pub keypair: Option<String>,
pub mint: String,
pub metadata: String,
pub immutable: bool,
pub priority: Priority,
}

pub fn create_metadata(args: CreateMetadataArgs) -> Result<()> {
Expand Down Expand Up @@ -59,7 +67,7 @@ pub fn create_metadata(args: CreateMetadataArgs) -> Result<()> {
print_supply: None,
};

let ix = CreateBuilder::new()
let create_ix = CreateBuilder::new()
.metadata(metadata_pubkey)
.mint(mint_pubkey, false)
.authority(keypair.pubkey())
Expand All @@ -68,7 +76,22 @@ pub fn create_metadata(args: CreateMetadataArgs) -> Result<()> {
.create_args(create_args)
.instruction();

let instructions = vec![ix];
let compute_units = get_compute_units(&args.client, &[create_ix.clone()], &[&keypair])?
.unwrap_or(DEFAULT_COMPUTE_UNITS);

let micro_lamports = match args.priority {
Priority::None => 20,
Priority::Low => 20_000,
Priority::Medium => 200_000,
Priority::High => 1_000_000,
Priority::Max => 2_000_000,
};

let instructions = vec![
ComputeBudgetInstruction::set_compute_unit_limit(compute_units as u32),
ComputeBudgetInstruction::set_compute_unit_price(micro_lamports),
create_ix,
];

let sig = send_and_confirm_transaction(&args.client, keypair, &instructions)?;

Expand All @@ -85,6 +108,7 @@ pub struct CreateFungibleArgs {
pub decimals: u8,
pub initial_supply: Option<f64>,
pub immutable: bool,
pub priority: Priority,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -141,7 +165,7 @@ pub fn create_fungible(args: CreateFungibleArgs) -> Result<()> {
print_supply: None,
};

let ix = CreateBuilder::new()
let create_ix = CreateBuilder::new()
.metadata(metadata_pubkey)
.mint(mint.pubkey(), true)
.authority(keypair.pubkey())
Expand All @@ -150,7 +174,7 @@ pub fn create_fungible(args: CreateFungibleArgs) -> Result<()> {
.create_args(create_args)
.instruction();

let mut instructions = vec![ix];
let mut instructions = vec![create_ix];

if let Some(initial_supply) = args.initial_supply {
// Convert float to native token units
Expand Down Expand Up @@ -180,7 +204,30 @@ pub fn create_fungible(args: CreateFungibleArgs) -> Result<()> {
instructions.push(mint_to_ix);
}

let sig = send_and_confirm_tx(&args.client, &[&keypair, &mint], &instructions)?;
let signers = vec![&keypair, &mint];

let compute_units =
get_compute_units(&args.client, &instructions, &signers)?.unwrap_or(DEFAULT_COMPUTE_UNITS);

let micro_lamports = match args.priority {
Priority::None => 20,
Priority::Low => 20_000,
Priority::Medium => 200_000,
Priority::High => 1_000_000,
Priority::Max => 2_000_000,
};

instructions.splice(
0..0,
vec![
ComputeBudgetInstruction::set_compute_unit_limit(compute_units as u32),
ComputeBudgetInstruction::set_compute_unit_price(micro_lamports),
],
);

println!("Instructions: {}", instructions.len());

let sig = send_and_confirm_tx(&args.client, &signers, &instructions)?;

println!("Signature: {sig}");
println!("Mint: {}", mint.pubkey());
Expand All @@ -195,6 +242,7 @@ pub struct CreateMasterEditionArgs {
pub mint_authority: Option<PathBuf>,
pub mint: Pubkey,
pub max_supply: i64,
pub priority: Priority,
}

pub fn create_master_edition(args: CreateMasterEditionArgs) -> Result<()> {
Expand Down Expand Up @@ -233,11 +281,30 @@ pub fn create_master_edition(args: CreateMasterEditionArgs) -> Result<()> {
}
let ix = builder.instruction();

let signers = vec![&keypair, &mint_authority];

let compute_units =
get_compute_units(&args.client, &[ix.clone()], &signers)?.unwrap_or(DEFAULT_COMPUTE_UNITS);

let micro_lamports = match args.priority {
Priority::None => 20,
Priority::Low => 20_000,
Priority::Medium => 200_000,
Priority::High => 1_000_000,
Priority::Max => 2_000_000,
};

let instructions = vec![
ComputeBudgetInstruction::set_compute_unit_limit(compute_units as u32),
ComputeBudgetInstruction::set_compute_unit_price(micro_lamports),
ix,
];

let recent_blockhash = args.client.get_latest_blockhash()?;
let tx = Transaction::new_signed_with_payer(
&[ix],
&instructions,
Some(&keypair.pubkey()),
&[&keypair, &mint_authority],
&signers,
recent_blockhash,
);

Expand Down