Skip to content

Commit

Permalink
Add support for prioritizationFeeLamports swap field. Swap priority f…
Browse files Browse the repository at this point in the history
…ee is now auto by default (#15)
  • Loading branch information
mvines authored Apr 17, 2024
1 parent 400fa5e commit 7b40509
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/field_prioritization_fee.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use {crate::PrioritizationFeeLamports, serde::Serialize, serde::Serializer};

pub fn serialize<S>(
prioritization_fee_lamports: &PrioritizationFeeLamports,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match prioritization_fee_lamports {
PrioritizationFeeLamports::Auto => "auto".serialize(serializer),
PrioritizationFeeLamports::Exact { lamports } => lamports.serialize(serializer),
}
}
14 changes: 13 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use {

mod field_as_string;
mod field_instruction;
mod field_prioritization_fee;
mod field_pubkey;

/// A `Result` alias where the `Err` case is `jup_ag::Error`.
Expand Down Expand Up @@ -272,6 +273,12 @@ pub async fn quote(
maybe_jupiter_api_error(reqwest::get(url).await?.json().await?)
}

#[derive(Debug)]
pub enum PrioritizationFeeLamports {
Auto,
Exact { lamports: u64 },
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[allow(non_snake_case)]
Expand All @@ -282,7 +289,10 @@ pub struct SwapRequest {
pub use_shared_accounts: Option<bool>,
#[serde(with = "field_pubkey::option")]
pub fee_account: Option<Pubkey>,
#[deprecated = "please use SwapRequest::prioritization_fee_lamports instead"]
pub compute_unit_price_micro_lamports: Option<u64>,
#[serde(with = "field_prioritization_fee")]
pub prioritization_fee_lamports: PrioritizationFeeLamports,
pub as_legacy_transaction: Option<bool>,
pub use_token_ledger: Option<bool>,
#[serde(with = "field_pubkey::option")]
Expand All @@ -293,12 +303,14 @@ pub struct SwapRequest {
impl SwapRequest {
/// Creates new SwapRequest with the given and default values
pub fn new(user_public_key: Pubkey, quote_response: Quote) -> Self {
#[allow(deprecated)]
SwapRequest {
user_public_key,
wrap_and_unwrap_sol: Some(true),
use_shared_accounts: Some(true),
fee_account: None,
compute_unit_price_micro_lamports: None, // Tested with reqbin if null the value will work, most likely then using "auto"
compute_unit_price_micro_lamports: None,
prioritization_fee_lamports: PrioritizationFeeLamports::Auto,
as_legacy_transaction: Some(false),
use_token_ledger: Some(false),
destination_token_account: None,
Expand Down

0 comments on commit 7b40509

Please sign in to comment.