Skip to content

Commit

Permalink
Added ComputeBudgetProgram to enable priority fees for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
BifrostTitan committed Apr 25, 2023
1 parent 868aff4 commit 21fdbce
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/Solnet.Programs/ComputeBudgetProgram.cs
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
};
}

}
}

0 comments on commit 21fdbce

Please sign in to comment.