Skip to content

Jupiter swap extension #58

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

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
38 changes: 38 additions & 0 deletions src/Solana.Unity.Dex/Jupiter/Core/Types/Http/SwapRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,42 @@ public class SwapRequest
/// Is this a legacy transaction
/// </summary>
public bool AsLegacyTransaction { get; set; }

/// <summary>
/// To specify a level or amount of additional fees to prioritize the transaction
/// It can be used for both priority fee and jito tip
/// </summary>
public PrioritizationFeeLamportsContainer PrioritizationFeeLamports { get; set; }
}

/// <summary>
/// Represents prioritization fee settings
/// </summary>
public class PrioritizationFeeLamportsContainer
{
/// <summary>
/// Represents the max Lamports and priority level
/// </summary>
public PriorityLevelWithMaxLamports PriorityLevelWithMaxLamports { get; set; }
/// <summary>
/// Exact amount of tip to use in a tip instruction
/// Estimate how much to set using Jito tip endpoint, see https://docs.jito.wtf/
/// </summary>
public int JitoTipLamports { get; set; }
}

/// <summary>
/// Represents the max Lamports and priority level
/// </summary>
public class PriorityLevelWithMaxLamports
{
/// <summary>
/// Maximum lamports to cap the priority fee estimation, to prevent overpaying
/// </summary>
public ulong MaxLamports { get; set; }

/// <summary>
/// Either medium, high or veryHigh
/// </summary>
public string PriorityLevel { get; set; } // Example: "veryHigh"
}
21 changes: 19 additions & 2 deletions src/Solana.Unity.Dex/Jupiter/JupiterDex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,29 @@
bool useSharedAccounts = true,
PublicKey feeAccount = null,
BigInteger? computeUnitPriceMicroLamports = null,
bool useTokenLedger = false)
bool useTokenLedger = false,
ulong maxLamports = 1_400_000,
string priorityLevel = "medium",
int jitoTipLamports = 0
)
{
userPublicKey ??= _account;

// Construct the request URL
var apiUrl = _endpoint + "/swap";

var priorityLevelObject = new PriorityLevelWithMaxLamports()
{
MaxLamports = maxLamports,
PriorityLevel = priorityLevel
}

Check failure on line 154 in src/Solana.Unity.Dex/Jupiter/JupiterDex.cs

View workflow job for this annotation

GitHub Actions / build

; expected

Check failure on line 154 in src/Solana.Unity.Dex/Jupiter/JupiterDex.cs

View workflow job for this annotation

GitHub Actions / build

; expected

var prioritizationFeePart = new PrioritizationFeeLamportsContainer()
{
PriorityLevelWithMaxLamports = priorityLevelObject,
JitoTipLamports = jitoTipLamports
}

Check failure on line 160 in src/Solana.Unity.Dex/Jupiter/JupiterDex.cs

View workflow job for this annotation

GitHub Actions / build

; expected

Check failure on line 160 in src/Solana.Unity.Dex/Jupiter/JupiterDex.cs

View workflow job for this annotation

GitHub Actions / build

; expected

var req = new SwapRequest()
{
QuoteResponse = quoteResponse,
Expand All @@ -153,7 +169,8 @@
FeeAccount = feeAccount,
ComputeUnitPriceMicroLamports = computeUnitPriceMicroLamports,
UseTokenLedger = useTokenLedger,
AsLegacyTransaction = false
AsLegacyTransaction = false,
PrioritizationFeeLamports = prioritizationFeePart
};

var requestJson = JsonConvert.SerializeObject(req, _serializerOptions);
Expand Down
Loading