-
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.
Merge pull request #3 from avianlabs/add-compute-budget-program
add compute budget program
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...-kotlin/src/commonMain/kotlin/net/avianlabs/solana/domain/program/ComputeBudgetProgram.kt
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,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(), | ||
) | ||
} |