forked from p2p-org/solana-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ComputeBudgetProgram to be able to set transaction priority fees
- Loading branch information
Alexander Manzer
committed
Mar 20, 2024
1 parent
4f6e551
commit 57d3c1f
Showing
1 changed file
with
35 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,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] | ||
) | ||
} | ||
} |