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

feat: smart tx optional prority fee #85

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/send_smart_transaction_with_tip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async fn main() {
signers: vec![&from_keypair],
lookup_tables: None,
fee_payer: None,
priority_fee: None,
};

let config: SmartTransactionConfig = SmartTransactionConfig {
Expand Down
27 changes: 18 additions & 9 deletions src/optimized_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,27 @@ impl Helius {
}),
};

// Send the request to get the priority fee estimate
let priority_fee_estimate: GetPriorityFeeEstimateResponse =
self.rpc().get_priority_fee_estimate(priority_fee_request).await?;

let priority_fee_recommendation: u64 =
// Extract the estimated priority fee, or return an error if not available
let priority_fee_estimate = priority_fee_estimate
.priority_fee_estimate
.ok_or(HeliusError::InvalidInput(
"Priority fee estimate not available".to_string(),
))? as u64;

// Determine the priority fee for the transaction
let priority_fee: u64 = if let Some(provided_fee) = config.priority_fee {
// Take the minimum between the estimate and the user-provided cap
std::cmp::min(priority_fee_estimate, provided_fee)
} else {
priority_fee_estimate
.priority_fee_estimate
.ok_or(HeliusError::InvalidInput(
"Priority fee estimate not available".to_string(),
))? as u64;

// Add the compute unit price instruction with the estimated fee
let compute_budget_ix: Instruction =
ComputeBudgetInstruction::set_compute_unit_price(priority_fee_recommendation);
};

// Add the compute unit price instruction with the priority fee
let compute_budget_ix: Instruction = ComputeBudgetInstruction::set_compute_unit_price(priority_fee);
let mut updated_instructions: Vec<Instruction> = config.instructions.clone();
updated_instructions.push(compute_budget_ix.clone());
final_instructions.push(compute_budget_ix);
Expand Down Expand Up @@ -443,6 +451,7 @@ impl Helius {
signers: signer_refs,
lookup_tables: create_config.lookup_tables,
fee_payer: Some(&signers[fee_payer_index] as &dyn Signer),
priority_fee: create_config.priority_fee,
};

let smart_transaction_config: SmartTransactionConfig<'_> = SmartTransactionConfig {
Expand Down
4 changes: 4 additions & 0 deletions src/types/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ pub struct CreateSmartTransactionConfig<'a> {
pub signers: Vec<&'a dyn Signer>,
pub lookup_tables: Option<Vec<AddressLookupTableAccount>>,
pub fee_payer: Option<&'a dyn Signer>,
pub priority_fee: Option<u64>,
}

impl<'a> CreateSmartTransactionConfig<'a> {
Expand All @@ -964,6 +965,7 @@ impl<'a> CreateSmartTransactionConfig<'a> {
signers,
lookup_tables: None,
fee_payer: None,
priority_fee: None,
}
}
}
Expand Down Expand Up @@ -1015,6 +1017,7 @@ pub struct CreateSmartTransactionSeedConfig {
pub signer_seeds: Vec<[u8; 32]>,
pub fee_payer_seed: Option<[u8; 32]>,
pub lookup_tables: Option<Vec<AddressLookupTableAccount>>,
pub priority_fee: Option<u64>,
}

impl CreateSmartTransactionSeedConfig {
Expand All @@ -1024,6 +1027,7 @@ impl CreateSmartTransactionSeedConfig {
signer_seeds,
fee_payer_seed: None,
lookup_tables: None,
priority_fee: None,
}
}

Expand Down
Loading