spl_token

package
v0.0.0-...-07d62d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// VariantInitialiseAccount to initialise a spl token account
	VariantInitialiseAccount = 1

	// VariantTransfer to transfer an amount to a user
	VariantTransfer = 3

	// VariantMintTo to mint tokens to a user
	VariantMintTo = 7

	// VariantBurn to burn tokens from a user
	VariantBurn = 8

	// VariantTransferChecked to transfer an amount,
	// verifying the expected token decimals
	VariantTransferChecked = 12
)
View Source
const (
	// TokenProgramAddress to use as the SPL token
	TokenProgramAddress = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"

	// TokenAssociatedProgramAddress used to create accounts
	TokenAssociatedProgramAddress = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"

	// WrappedSolMintAddress used to wrap sol into an SPL token
	WrappedSolMintAddress = "So11111111111111111111111111111111111111112"

	// WrappedSolDecimals to calculate decimals for the wrapped sol token
	WrappedSolDecimals = 9
)

Variables

View Source
var (
	// TokenProgramAddressPubkey
	TokenProgramAddressPubkey solLib.PublicKey

	// TokenAssociatedProgramAddressPubkey
	TokenAssociatedProgramAddressPubkey solLib.PublicKey

	// WrappedSolMintAddressPubkey
	WrappedSolMintAddressPubkey solLib.PublicKey
)

initialised in init.go

View Source
var UnknownInstructionError = solana.UnknownInstructionError

Functions

func AdjustDecimals

func AdjustDecimals(rawAmount int64, decimals int) *big.Rat

AdjustDecimals takens a rawAmount (int64) and an number of decimals and returns a rat of the rawAmount adjusted to that many decimal places

func GetDecimalsFromMint

func GetDecimalsFromMint(solanaClient *rpc.Provider, splAccount solana.PublicKey) (uint8, error)

GetDecimals by taking an spl-token mint account, getting its data from the chain, and deserialising to get the decimals

func GetDecimalsFromPda

func GetDecimalsFromPda(solanaClient *rpc.Provider, account solana.PublicKey, commitment string) (uint8, error)

GetDecimalsFromPda to get a token's decimals from a PDA of that token

func GetMintFromPda

func GetMintFromPda(solanaClient *rpc.Provider, splAccount solana.PublicKey) (solana.PublicKey, error)

GetMintFromPda by taking an spl-token user account, getting its data from the chain, and deserialising to get the mint account

func IsInitialiseAccount

func IsInitialiseAccount(data string) (bool, error)

IsInitialiseAccount returns if an instruction is an InitialiseAccount

func SendTransfer

func SendTransfer(solanaClient *rpc.Provider, senderPdaAddress, recipientAddress, tokenMintAddress solLib.PublicKey, amount uint64, recentBlockHash solLib.Hash, ownerPublicKey solLib.PublicKey, ownerPrivateKey solLib.PrivateKey) (string, error)

SendTransfer using the token address given, the sender address, returning the signature or an error

Types

type InstructionTransfer

type InstructionTransfer struct {
	Variant uint8
	Amount  uint64
}

InstructionTransfer generally used with VariantTransfer to send amounts

type SplBurn

type SplBurn struct {
	Amount uint64
}

SplBurn represents Burn(u64), burning a token from an account

type SplInstruction

type SplInstruction struct {
	Transfer        *SplTransfer
	MintTo          *SplMintTo
	Burn            *SplBurn
	TransferChecked *SplTransferChecked
}

SplInstruction is a container storing a single variant of the decoded SPL Token instruction enum

func DecodeSplUserAction

func DecodeSplUserAction(data string) (SplInstruction, error)

DecodeSplUserAction tries to decode base58 encoded solana transaction data into one of the SPL token instructions we care about for user actions

type SplMintAccountTruncated

type SplMintAccountTruncated struct {
	MintAuthority   [36]byte
	Supply          uint64
	Decimals        uint8
	Initialised     bool
	FreezeAuthority [36]byte
}

SplMintAccountTruncated is a truncated version of the spl-token mint account struct, used to get the decimals

type SplMintTo

type SplMintTo struct {
	Amount uint64
}

SplMintTo represents MintTo(u64), minting a token to an account

type SplTransfer

type SplTransfer struct {
	Amount uint64
}

SplTransfer represents Transfer(u64), transfering an SPL token between two accounts

type SplTransferChecked

type SplTransferChecked struct {
	Amount   uint64
	Decimals uint8
}

SplTransferChecked represents TransferChecked(u64, u8), transfering a token between two accounts with verification of the token decimals

type SplUserAccountTruncated

type SplUserAccountTruncated struct {
	Mint solana.PublicKey
}

SplUserAccountTruncated is a truncated version of the spl-token user account struct, used to get the mint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL