Skip to content

Commit

Permalink
Add ComputeBudgetProgram to be able to set transaction priority fees
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Manzer committed Mar 20, 2024
1 parent 4f6e551 commit 57d3c1f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Sources/SolanaSwift/Programs/ComputeBudgetProgram.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Foundation

public enum ComputeBudgetProgram: SolanaBasicProgram {
// MARK: - Nested type

public enum Index {
static let requestUnits: UInt8 = 0
static let requestHeapFrame: UInt8 = 1
static let setComputeUnitLimit: UInt8 = 2
static let setComputeUnitPrice: UInt8 = 3
}

/// The public id of the program
public static var id: PublicKey {
"ComputeBudget111111111111111111111111111111"
}

/// Create SetComputeUnitPrice instruction
public static func createSetComputeUnitPriceInstruction(microLamports: UInt64) throws -> TransactionInstruction {
TransactionInstruction(
keys: [],
programId: id,
data: [Index.setComputeUnitPrice, microLamports]
)
}

/// Create SetComputeUnitLimit instruction
public static func createSetComputeUnitLimitInstruction(limit: UInt32) throws -> TransactionInstruction {
TransactionInstruction(
keys: [],
programId: id,
data: [Index.setComputeUnitLimit, limit]
)
}
}

0 comments on commit 57d3c1f

Please sign in to comment.