From 70dd204a80205bef6934db399450dafd19a4d25b Mon Sep 17 00:00:00 2001 From: MoneyCollector Date: Sat, 22 Feb 2025 08:47:34 +0100 Subject: [PATCH] Added Jupiter PrioritieFees parameter and MaxLamports configuration. --- .../Jupiter/Core/Types/Http/SwapRequest.cs | 33 +++++++++++++++++++ src/Solana.Unity.Dex/Jupiter/JupiterDex.cs | 19 +++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/Solana.Unity.Dex/Jupiter/Core/Types/Http/SwapRequest.cs b/src/Solana.Unity.Dex/Jupiter/Core/Types/Http/SwapRequest.cs index 8891dc34..aa3438d9 100644 --- a/src/Solana.Unity.Dex/Jupiter/Core/Types/Http/SwapRequest.cs +++ b/src/Solana.Unity.Dex/Jupiter/Core/Types/Http/SwapRequest.cs @@ -53,4 +53,37 @@ public class SwapRequest /// Is this a legacy transaction /// public bool AsLegacyTransaction { get; set; } + + /// + /// To specify a level or amount of additional fees to prioritize the transaction + /// It can be used for both priority fee and jito tip + /// + public PrioritizationFeeLamportsContainer PrioritizationFeeLamports { get; set; } +} + +/// +/// Represents prioritization fee settings +/// +public class PrioritizationFeeLamportsContainer +{ + /// + /// Represents the max Lamports and priority level + /// + public PriorityLevelWithMaxLamports PriorityLevelWithMaxLamports { get; set; } +} + +/// +/// Represents the max Lamports and priority level +/// +public class PriorityLevelWithMaxLamports +{ + /// + /// Maximum lamports to cap the priority fee estimation, to prevent overpaying + /// + public ulong MaxLamports { get; set; } + + /// + /// Either medium, high or veryHigh + /// + public string PriorityLevel { get; set; } // Example: "veryHigh" } \ No newline at end of file diff --git a/src/Solana.Unity.Dex/Jupiter/JupiterDex.cs b/src/Solana.Unity.Dex/Jupiter/JupiterDex.cs index 50b83eba..c9611247 100644 --- a/src/Solana.Unity.Dex/Jupiter/JupiterDex.cs +++ b/src/Solana.Unity.Dex/Jupiter/JupiterDex.cs @@ -136,13 +136,27 @@ public async Task Swap( bool useSharedAccounts = true, PublicKey feeAccount = null, BigInteger? computeUnitPriceMicroLamports = null, - bool useTokenLedger = false) + bool useTokenLedger = false, + ulong maxLamports = 1_400_000, + string priorityLevel = "medium" + ) { userPublicKey ??= _account; // Construct the request URL var apiUrl = _endpoint + "/swap"; + var priorityLevelObject = new PriorityLevelWithMaxLamports() + { + MaxLamports = maxLamports, + PriorityLevel = priorityLevel + }; + + var prioritizationFeePart = new PrioritizationFeeLamportsContainer() + { + PriorityLevelWithMaxLamports = priorityLevelObject + }; + var req = new SwapRequest() { QuoteResponse = quoteResponse, @@ -153,7 +167,8 @@ public async Task Swap( FeeAccount = feeAccount, ComputeUnitPriceMicroLamports = computeUnitPriceMicroLamports, UseTokenLedger = useTokenLedger, - AsLegacyTransaction = false + AsLegacyTransaction = false, + PrioritizationFeeLamports = prioritizationFeePart }; var requestJson = JsonConvert.SerializeObject(req, _serializerOptions);