Skip to content

Commit

Permalink
Merge pull request #3 from avianlabs/add-compute-budget-program
Browse files Browse the repository at this point in the history
add compute budget program
  • Loading branch information
wiyarmir authored Feb 1, 2024
2 parents 10fc8a6 + 1dbe449 commit 055ef05
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.avianlabs.solana.domain.program

import net.avianlabs.solana.domain.core.PublicKey
import net.avianlabs.solana.domain.core.TransactionInstruction
import okio.Buffer

private val TOKEN_PROGRAM_ID = PublicKey.fromBase58("ComputeBudget111111111111111111111111111111")

public object ComputeBudgetProgram : Program(
programId = TOKEN_PROGRAM_ID,
) {

public enum class Instruction(
public val index: UByte,
) {
RequestUnits(0u),
RequestHeapFrames(1u),
SetComputeUnitLimit(2u),
SetComputeUnitPrice(3u),
;
}

/**
* @param microLamports Transaction compute unit price used for prioritization fees.
*/
public fun setComputeUnitPrice(
microLamports: ULong,
): TransactionInstruction = createTransactionInstruction(
programId = programId,
keys = listOf(
),
data = Buffer()
.writeByte(Instruction.SetComputeUnitPrice.index.toInt())
.writeLongLe(microLamports.toLong())
.readByteArray(),
)
}

0 comments on commit 055ef05

Please sign in to comment.