types

package
v0.1.7-beta Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: AGPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AccountSize       uint64 = 165 // 165 bytes
	FeeCalculatorSize uint64 = 8   // 8 bytes
	NonceAccountSize  uint64 = 80  // 80 bytes
	StakeAccountSize  uint64 = 200 // 200 bytes
	TokenAccountSize  uint64 = 165 // 165 bytes
	MintAccountSize   uint64 = 82  // 82 bytes
)

Predefined Solana account sizes

View Source
const (
	LookupTableMetaSize     uint64 = 56  // 56 bytes
	LookupTableMaxAddresses uint   = 256 // 256 addresses
)

Lookup table sizes

View Source
const (
	// Solana Devnet RPC URL
	SolanaDevnetRPCURL = "https://api.devnet.solana.com"

	// Solana Mainnet RPC URL
	SolanaMainnetRPCURL = "https://api.mainnet-beta.solana.com"

	// Solana Testnet RPC URL
	SolanaTestnetRPCURL = "https://api.testnet.solana.com"
)
View Source
const (
	// 1 SOL = 1e9 lamports
	SOL uint64 = 1e9

	// SPL token default decimals
	SPLTokenDefaultDecimals uint8 = 9

	// SPL token default multiplier for decimals
	SPLTokenDefaultMultiplier uint64 = 1e9

	// Wrapped SOL mint address
	WrappedSOLMint = "So11111111111111111111111111111111111111112"

	// DeprecatedTokenListPath is the default token list path
	DeprecatedTokenListPath = "https://raw.githubusercontent.com/solana-labs/token-list/main/src/tokens/solana.tokenlist.json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type RPCTokenAccount

type RPCTokenAccount struct {
	Pubkey  string `json:"pubkey"`
	Account struct {
		Lamports  uint64 `json:"lamports"`
		Owner     string `json:"owner"`
		RentEpoch uint64 `json:"rentEpoch"`
		Data      struct {
			Parsed struct {
				Info struct {
					IsNative    bool   `json:"isNative"`
					Mint        string `json:"mint"`
					Owner       string `json:"owner"`
					State       string `json:"state"`
					TokenAmount struct {
						Amount         string  `json:"amount"`
						Decimals       uint8   `json:"decimals"`
						UIAmount       float64 `json:"uiAmount"`
						UIAmountString string  `json:"uiAmountString"`
					} `json:"tokenAmount"`
					Delegate        *string `json:"delegate"`
					DelegatedAmount *struct {
						Amount         string  `json:"amount"`
						Decimals       uint8   `json:"decimals"`
						UIAmount       float64 `json:"uiAmount"`
						UIAmountString string  `json:"uiAmountString"`
					} `json:"delegatedAmount"`
				} `json:"info"`
				Type string `json:"type"`
			} `json:"parsed"`
			Program string `json:"program"`
			Space   uint64 `json:"space"`
		} `json:"data"`
		Executable bool `json:"executable"`
	} `json:"account"`
}

*

RPCTokenAccount represents the following json data:
{
	"pubkey": "DUNMHHh3qLwd7zVfckWHK7DoAk7jaeHiJgouVEQGraEe",
	"account": {
		"lamports": 2039280,
		"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
		"rentEpoch": 0,
		"data": {
			"parsed": {
				"info": {
					"isNative": false,
					"mint": "DCQqijZDH6a14o3wQcF8KzrBtsCjTBgfmagYYvQS8ihB",
					"owner": "FuQhSmAT6kAmmzCMiiYbzFcTQJFuu6raXAdCFibz4YPR",
					"state": "initialized",
					"tokenAmount": {
						"amount": "1",
						"decimals": 0,
						"uiAmount": 1,
						"uiAmountString": "1"
					},
					"delegate": "GKv5PeCxKBCDezo4FMVjjRbkUfoou9PRvPKdzaFEwjXi",
					"delegatedAmount": {
						"amount": "1",
						"decimals": 0,
						"uiAmount": 1,
						"uiAmountString": "1"
					},
				},
				"type": "account"
			},
			"program": "spl-token",
			"space": 165
		},
		"executable": false
	}
}

type TokenAccount

type TokenAccount struct {
	Pubkey           common.PublicKey  `json:"pubkey"`
	Mint             common.PublicKey  `json:"mint"`
	Owner            common.PublicKey  `json:"owner"`
	State            TokenAccountState `json:"state"`
	IsNative         bool              `json:"is_native"` // if is wrapped SOL, IsNative is the rent-exempt value
	Balance          TokenAmount       `json:"balance"`
	Delegate         *common.PublicKey `json:"delegate,omitempty"`
	DelegatedBalance *TokenAmount      `json:"delegated_balance,omitempty"`
}

The account that holds the token

func NewTokenAccount

func NewTokenAccount(data []byte) (TokenAccount, error)

NewTokenAccount converts the given json encoded data to a token account.

func (TokenAccount) IsEmpty

func (a TokenAccount) IsEmpty() bool

IsEmpty returns true if the token account is empty.

func (TokenAccount) IsFungibleAsset

func (a TokenAccount) IsFungibleAsset() bool

IsFungibleAsset returns true if the token account is a fungible asset.

func (TokenAccount) IsFungibleToken

func (a TokenAccount) IsFungibleToken() bool

IsFungibleToken returns true if the token account is a fungible token.

func (TokenAccount) IsNFT

func (a TokenAccount) IsNFT() bool

IsNFT returns true if the token account is an NFT.

type TokenAccountState

type TokenAccountState string
const (
	TokenAccountStateUninitialized TokenAccountState = "uninitialized"
	TokenAccountStateInitialized   TokenAccountState = "initialized"
	TokenAccountFrozen             TokenAccountState = "frozen"
)

Predefined token account states.

func (TokenAccountState) String

func (s TokenAccountState) String() string

String returns the string representation of the token account state.

type TokenAmount

type TokenAmount struct {
	Amount         uint64  `json:"amount"`                     // amount in token lamports
	Decimals       uint8   `json:"decimals,omitempty"`         // number of decimals for the token; max 9
	UIAmount       float64 `json:"ui_amount,omitempty"`        // amount in token units, e.g. 1 SOL
	UIAmountString string  `json:"ui_amount_string,omitempty"` // amount in token units as a string, e.g. "1.000000000"
}

TokenAmount represents the amount of a token.

func NewDefaultTokenAmount

func NewDefaultTokenAmount(lamports uint64) TokenAmount

NewDefaultTokenAmount converts the given lamports to a token amount with the default decimals.

func NewTokenAmountFromLamports

func NewTokenAmountFromLamports(lamports uint64, decimals uint8) TokenAmount

TokenAmountFromLamports converts the given lamports to a token amount.

type TransactionStatus

type TransactionStatus uint8

TransactionStatus represents the status of a transaction.

const (
	TransactionStatusUnknown TransactionStatus = iota
	TransactionStatusSuccess
	TransactionStatusInProgress
	TransactionStatusFailure
)

TransactionStatus enum.

func ParseTransactionStatus

func ParseTransactionStatus(s rpc.Commitment) TransactionStatus

ParseTransactionStatus parses the transaction status from the given string.

func (TransactionStatus) String

func (s TransactionStatus) String() string

String returns the string representation of the transaction status.

Jump to

Keyboard shortcuts

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