Skip to content

Commit b8e3ab9

Browse files
Add ComputeBudgetProgram
1 parent 064bd43 commit b8e3ab9

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

Sources/SolanaSwift/BlockchainClient/BlockchainClient.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ public class BlockchainClient: SolanaBlockchainClient {
2626
feePayer: PublicKey
2727
) async throws -> PreparedTransaction {
2828
// form transaction
29-
var transaction = Transaction(instructions: instructions, recentBlockhash: nil, feePayer: feePayer)
30-
3129
let blockhash = try await apiClient.getLatestBlockhash()
32-
transaction.recentBlockhash = blockhash
30+
var transaction = Transaction(instructions: instructions, recentBlockhash: blockhash, feePayer: feePayer)
3331

3432
// if any signers, sign
3533
if !signers.isEmpty {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// File.swift
3+
// SolanaSwift
4+
//
5+
// Created by Maksym Vereshchaka on 23.01.2025.
6+
//
7+
8+
import Foundation
9+
10+
public enum ComputeBudgetProgram: SolanaBasicProgram {
11+
12+
// MARK: - Nested type
13+
14+
public enum Index {
15+
static let requestUnits: UInt8 = 0
16+
static let requestHeapFrame: UInt8 = 1
17+
static let setComputeUnitLimit: UInt8 = 2
18+
static let setComputeUnitPrice: UInt8 = 3
19+
}
20+
21+
/// The public id of the program
22+
public static var id: PublicKey {
23+
"ComputeBudget111111111111111111111111111111"
24+
}
25+
26+
/// Create SetComputeUnitPrice instruction
27+
public static func createSetComputeUnitPriceInstruction(microLamports: UInt64) throws -> TransactionInstruction {
28+
TransactionInstruction(
29+
keys: [],
30+
programId: id,
31+
data: [Index.setComputeUnitPrice, microLamports]
32+
)
33+
}
34+
35+
/// Create SetComputeUnitLimit instruction
36+
public static func createSetComputeUnitLimitInstruction(limit: UInt32) throws -> TransactionInstruction {
37+
TransactionInstruction(
38+
keys: [],
39+
programId: id,
40+
data: [Index.setComputeUnitLimit, limit]
41+
)
42+
}
43+
}

0 commit comments

Comments
 (0)