-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ComputeBudgetProgram to enable priority fees for transactions
- Loading branch information
1 parent
868aff4
commit 21fdbce
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using Solnet.Programs.Utilities; | ||
using Solnet.Rpc.Models; | ||
using Solnet.Wallet; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Solnet.Programs | ||
{ | ||
/// <summary> | ||
/// Implements the ComputeBudget Program methods. | ||
/// <remarks> | ||
/// For more information see: https://spl.solana.com/memo | ||
/// </remarks> | ||
/// </summary> | ||
|
||
public class ComputeBudgetProgram | ||
{ | ||
|
||
/// <summary> | ||
/// The public key of the ComputeBudget Program. | ||
/// </summary> | ||
public static readonly PublicKey ProgramIdKey = new("ComputeBudget111111111111111111111111111111"); | ||
|
||
|
||
/// <summary> | ||
/// The program's name. | ||
/// </summary> | ||
private const string ProgramName = "Compute Budget Program"; | ||
|
||
|
||
|
||
/// <summary> | ||
/// Request HeapFrame Instruction related to Priority Fees | ||
/// </summary> | ||
/// <param name="bytes"></param> | ||
/// <returns></returns> | ||
public static TransactionInstruction RequestHeapFrame(uint bytes) | ||
{ | ||
List<AccountMeta> keys = new(); | ||
|
||
byte[] instructionBytes = new byte[5]; | ||
instructionBytes.WriteU8(1, 0); | ||
instructionBytes.WriteU32(bytes, 1); | ||
|
||
return new TransactionInstruction | ||
{ | ||
ProgramId = ProgramIdKey.KeyBytes, | ||
Keys = keys, | ||
Data = instructionBytes | ||
}; | ||
} | ||
/// <summary> | ||
/// Set Compute Unit Limit Instruction for Priority Fees | ||
/// </summary> | ||
/// <param name="units"></param> | ||
/// <returns></returns> | ||
public static TransactionInstruction SetComputeUnitLimit(uint units) | ||
{ | ||
List<AccountMeta> keys = new(); | ||
|
||
byte[] instructionBytes = new byte[5]; | ||
instructionBytes.WriteU8(2, 0); | ||
instructionBytes.WriteU64(units, 1); | ||
|
||
return new TransactionInstruction | ||
{ | ||
ProgramId = ProgramIdKey.KeyBytes, | ||
Keys = keys, | ||
Data = instructionBytes | ||
}; | ||
} | ||
/// <summary> | ||
/// Set Compute Unit Price Instruction for Priority Fees | ||
/// </summary> | ||
/// <param name="priority_rate"></param> | ||
/// <returns></returns> | ||
public static TransactionInstruction SetComputeUnitPrice(ulong priority_rate) | ||
{ | ||
List<AccountMeta> keys = new(); | ||
|
||
byte[] instructionBytes = new byte[9]; | ||
instructionBytes.WriteU8(3, 0); | ||
instructionBytes.WriteU64(priority_rate, 1); | ||
|
||
return new TransactionInstruction | ||
{ | ||
ProgramId = ProgramIdKey.KeyBytes, | ||
Keys = keys, | ||
Data = instructionBytes | ||
}; | ||
} | ||
|
||
} | ||
} |