utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsBigInt

func AbsBigInt(value *big.Int) *big.Int

AbsBigInt returns the absolute value of a big.Int

func ContainsAny

func ContainsAny(slice []string, values ...string) bool

ContainsAny checks if any of the values exist in the slice

func DecodeInstructionData

func DecodeInstructionData(data interface{}) ([]byte, error)

DecodeInstructionData decodes instruction data from various formats

func FindAssociatedTokenAddress

func FindAssociatedTokenAddress(wallet, mint string) (standard, token2022 string, err error)

FindAssociatedTokenAddress computes the associated token address for a wallet and mint

func FormatDedupeKey

func FormatDedupeKey(idx, signature string) string

FormatDedupeKey formats a deduplication key for trades as "idx-signature"

func FormatIdx

func FormatIdx(outerIndex int, innerIndex int) string

FormatIdx formats instruction indices as string

func FormatTransferKey

func FormatTransferKey(programId string, outer, inner int) string

FormatTransferKey formats a transfer key as "programId:outer" or "programId:outer-inner"

func GetAMMs

func GetAMMs(transferActionKeys []string) []string

GetAMMs extracts AMM names from transfer action keys

func GetAccountTradeType

func GetAccountTradeType(userAccount, baseMint, inputUserAccount, outputUserAccount string) types.TradeType

GetAccountTradeType determines trade type based on user's token accounts

func GetFinalSwap

func GetFinalSwap(trades []types.TradeInfo, dexInfo *types.DexInfo) *types.TradeInfo

GetFinalSwap aggregates multiple trades into a single final swap

func GetPrevInstructionByIndex

func GetPrevInstructionByIndex(instructions []types.ClassifiedInstruction, outerIndex, innerIndex int) *types.ClassifiedInstruction

GetPrevInstructionByIndex finds the previous instruction in a list

func GetProgramName

func GetProgramName(programId string) string

GetProgramName returns the name of a program by its ID

func GetPubkeyString

func GetPubkeyString(value interface{}) string

GetPubkeyString converts various pubkey representations to string

func GetTradeType

func GetTradeType(inMint, outMint string) types.TradeType

GetTradeType determines the trade type based on input/output mints

func GetTransferTokenMint

func GetTransferTokenMint(token1, token2 string) string

GetTransferTokenMint determines the token mint from two options

func HexToBytes

func HexToBytes(hexStr string) ([]byte, error)

HexToBytes converts a hex string to byte slice

func IsCompiledExtraAction

func IsCompiledExtraAction(ix *adapter.UnifiedInstruction, actionType string) bool

IsCompiledExtraAction checks if a compiled instruction is an extra action

func IsCompiledNativeTransfer

func IsCompiledNativeTransfer(ix *adapter.UnifiedInstruction) bool

IsCompiledNativeTransfer checks if a compiled instruction is a native SOL transfer

func IsCompiledTransfer

func IsCompiledTransfer(ix *adapter.UnifiedInstruction) bool

IsCompiledTransfer checks if a compiled instruction is a transfer

func IsCompiledTransferCheck

func IsCompiledTransferCheck(ix *adapter.UnifiedInstruction) bool

IsCompiledTransferCheck checks if a compiled instruction is a transferChecked

func IsExtraAction

func IsExtraAction(ix *adapter.UnifiedInstruction, actionType string) bool

IsExtraAction checks if instruction is an extra action type

func IsNativeTransfer

func IsNativeTransfer(ix *adapter.UnifiedInstruction) bool

IsNativeTransfer checks if instruction is a native SOL transfer

func IsTransfer

func IsTransfer(ix *adapter.UnifiedInstruction) bool

IsTransfer checks if instruction is a transfer instruction

func IsTransferCheck

func IsTransferCheck(ix *adapter.UnifiedInstruction) bool

IsTransferCheck checks if instruction is a transferChecked instruction

func ProcessCompiledExtraAction

func ProcessCompiledExtraAction(ix *adapter.UnifiedInstruction, idx string, adapt *adapter.TransactionAdapter, actionType string) *types.TransferData

ProcessCompiledExtraAction processes compiled extra actions

func ProcessCompiledNativeTransfer

func ProcessCompiledNativeTransfer(ix *adapter.UnifiedInstruction, idx string, adapt *adapter.TransactionAdapter) *types.TransferData

ProcessCompiledNativeTransfer processes a compiled native SOL transfer

func ProcessCompiledTransfer

func ProcessCompiledTransfer(ix *adapter.UnifiedInstruction, idx string, adapt *adapter.TransactionAdapter) *types.TransferData

ProcessCompiledTransfer processes a compiled transfer instruction

func ProcessCompiledTransferCheck

func ProcessCompiledTransferCheck(ix *adapter.UnifiedInstruction, idx string, adapt *adapter.TransactionAdapter) *types.TransferData

ProcessCompiledTransferCheck processes a compiled transferChecked instruction

func ProcessExtraAction

func ProcessExtraAction(ix *adapter.UnifiedInstruction, idx string, adapt *adapter.TransactionAdapter, actionType string) *types.TransferData

ProcessExtraAction processes extra actions like mintTo, burn, etc.

func ProcessNativeTransfer

func ProcessNativeTransfer(ix *adapter.UnifiedInstruction, idx string, adapt *adapter.TransactionAdapter) *types.TransferData

ProcessNativeTransfer processes a native SOL transfer instruction

func ProcessTransfer

ProcessTransfer processes a parsed transfer instruction

func ProcessTransferCheck

func ProcessTransferCheck(ix *adapter.UnifiedInstruction, idx string, adapt *adapter.TransactionAdapter) *types.TransferData

ProcessTransferCheck processes a transferChecked instruction

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to the value

func SortByIdx

func SortByIdx[T interface{ GetIdx() string }](items []T) []T

SortByIdx sorts items by their idx field (format: "main-sub")

func SortTradesByIdx

func SortTradesByIdx(trades []types.TradeInfo) []types.TradeInfo

SortTradesByIdx sorts TradeInfo slice by idx

Types

type BinaryReader

type BinaryReader struct {
	// contains filtered or unexported fields
}

BinaryReader provides methods for reading binary data with offset tracking

func GetBinaryReader

func GetBinaryReader(buffer []byte) *BinaryReader

GetBinaryReader gets a BinaryReader from the pool and initializes it

func NewBinaryReader

func NewBinaryReader(buffer []byte) *BinaryReader

NewBinaryReader creates a new BinaryReader from a byte slice

func (*BinaryReader) Error

func (r *BinaryReader) Error() error

Error returns any accumulated error

func (*BinaryReader) GetBuffer

func (r *BinaryReader) GetBuffer() []byte

GetBuffer returns the underlying buffer

func (*BinaryReader) GetOffset

func (r *BinaryReader) GetOffset() int

GetOffset returns the current read position

func (*BinaryReader) HasError

func (r *BinaryReader) HasError() bool

HasError returns true if an error has occurred

func (*BinaryReader) ReadBool

func (r *BinaryReader) ReadBool() (bool, error)

ReadBool reads a boolean value (1 byte)

func (*BinaryReader) ReadFixedArray

func (r *BinaryReader) ReadFixedArray(length int) ([]byte, error)

ReadFixedArray reads a fixed-length byte array

func (*BinaryReader) ReadI128

func (r *BinaryReader) ReadI128() (lo uint64, hi int64, err error)

ReadI128 reads a signed 128-bit little-endian integer as two int64

func (*BinaryReader) ReadI64

func (r *BinaryReader) ReadI64() (int64, error)

ReadI64 reads a signed 64-bit little-endian integer

func (*BinaryReader) ReadPubkey

func (r *BinaryReader) ReadPubkey() (string, error)

ReadPubkey reads a 32-byte public key and returns it as base58 string

func (*BinaryReader) ReadString

func (r *BinaryReader) ReadString() (string, error)

ReadString reads a Borsh-encoded string (4-byte length prefix + UTF-8 data)

func (*BinaryReader) ReadU128

func (r *BinaryReader) ReadU128() (lo, hi uint64, err error)

ReadU128 reads an unsigned 128-bit little-endian integer as two uint64

func (*BinaryReader) ReadU128AsBigInt

func (r *BinaryReader) ReadU128AsBigInt() *big.Int

ReadU128AsBigInt reads a u128 and returns it as *big.Int (convenience method)

func (*BinaryReader) ReadU16

func (r *BinaryReader) ReadU16() (uint16, error)

ReadU16 reads an unsigned 16-bit little-endian integer

func (*BinaryReader) ReadU32

func (r *BinaryReader) ReadU32() (uint32, error)

ReadU32 reads an unsigned 32-bit little-endian integer

func (*BinaryReader) ReadU64

func (r *BinaryReader) ReadU64() (uint64, error)

ReadU64 reads an unsigned 64-bit little-endian integer

func (*BinaryReader) ReadU64AsBigInt

func (r *BinaryReader) ReadU64AsBigInt() *big.Int

ReadU64AsBigInt reads a u64 and returns it as *big.Int (convenience method)

func (*BinaryReader) ReadU8

func (r *BinaryReader) ReadU8() (uint8, error)

ReadU8 reads an unsigned 8-bit integer

func (*BinaryReader) Release

func (r *BinaryReader) Release()

Release returns the BinaryReader to the pool

func (*BinaryReader) Remaining

func (r *BinaryReader) Remaining() int

Remaining returns the number of unread bytes

func (*BinaryReader) SetOffset

func (r *BinaryReader) SetOffset(offset int) error

SetOffset sets the read position

func (*BinaryReader) Skip

func (r *BinaryReader) Skip(n int) error

Skip advances the offset by n bytes

func (*BinaryReader) Slice

func (r *BinaryReader) Slice(length int) ([]byte, error)

Slice returns a slice of the buffer from current offset

type TransactionUtils

type TransactionUtils struct {
	// contains filtered or unexported fields
}

TransactionUtils provides utility functions for transaction processing

func NewTransactionUtils

func NewTransactionUtils(adapter *adapter.TransactionAdapter) *TransactionUtils

NewTransactionUtils creates a new TransactionUtils instance

func (*TransactionUtils) AttachTokenTransferInfo

func (tu *TransactionUtils) AttachTokenTransferInfo(trade *types.TradeInfo, transferActions map[string][]types.TransferData) *types.TradeInfo

AttachTokenTransferInfo attaches token transfer info to trade

func (*TransactionUtils) AttachTradeFee

func (tu *TransactionUtils) AttachTradeFee(trade *types.TradeInfo) *types.TradeInfo

AttachTradeFee attaches fee information to trade

func (*TransactionUtils) AttachUserBalanceToLPs

func (tu *TransactionUtils) AttachUserBalanceToLPs(liquidities []types.PoolEvent) []types.PoolEvent

AttachUserBalanceToLPs attaches user balance changes to liquidities

func (*TransactionUtils) DetectBot added in v1.2.0

func (tu *TransactionUtils) DetectBot(trade *types.TradeInfo)

DetectBot detects trading bot from SOL transfers to known bot fee accounts

func (*TransactionUtils) FilterTransfersForInstruction

func (tu *TransactionUtils) FilterTransfersForInstruction(transferActions map[string][]types.TransferData, programId string, outerIndex int, innerIndex int, filterTypes []string) []types.TransferData

FilterTransfersForInstruction filters transfers for a specific instruction

func (*TransactionUtils) GetAdapter

func (tu *TransactionUtils) GetAdapter() *adapter.TransactionAdapter

GetAdapter returns the underlying adapter

func (*TransactionUtils) GetDexInfo

func (tu *TransactionUtils) GetDexInfo(classifier *classifier.InstructionClassifier) types.DexInfo

GetDexInfo extracts DEX information from transaction

func (*TransactionUtils) GetLPTransfers

func (tu *TransactionUtils) GetLPTransfers(transfers []types.TransferData) []types.TransferData

GetLPTransfers sorts and gets LP tokens

func (*TransactionUtils) GetTransferActions

func (tu *TransactionUtils) GetTransferActions(extraTypes []string) map[string][]types.TransferData

GetTransferActions extracts transfer actions from transaction

func (*TransactionUtils) GetTransferInfo

func (tu *TransactionUtils) GetTransferInfo(transferData types.TransferData, timestamp int64, signature string) *types.TransferInfo

GetTransferInfo converts TransferData to TransferInfo format

func (*TransactionUtils) GetTransferInfoList

func (tu *TransactionUtils) GetTransferInfoList(transferDataList []types.TransferData) []types.TransferInfo

GetTransferInfoList converts a list of TransferData to TransferInfo list

func (*TransactionUtils) GetTransferTokenInfo

func (tu *TransactionUtils) GetTransferTokenInfo(transfer *types.TransferData) *types.TokenInfo

GetTransferTokenInfo gets token info from transfer data

func (*TransactionUtils) GetTransfersForInstruction

func (tu *TransactionUtils) GetTransfersForInstruction(transferActions map[string][]types.TransferData, programId string, outerIndex int, innerIndex int, extraTypes []string) []types.TransferData

GetTransfersForInstruction gets transfers for a specific instruction

func (*TransactionUtils) ParseInstructionAction

func (tu *TransactionUtils) ParseInstructionAction(instruction interface{}, idx string, extraTypes []string) *types.TransferData

ParseInstructionAction parses instruction action for transfers

func (*TransactionUtils) ProcessMemeTransferData

func (tu *TransactionUtils) ProcessMemeTransferData(
	ci types.ClassifiedInstruction,
	event *types.MemeEvent,
	baseMint string,
	skipNative bool,
	transferStartIdx int,
	transferActions map[string][]types.TransferData,
) *types.MemeEvent

ProcessMemeTransferData processes transfer data for meme token events

func (*TransactionUtils) ProcessSwapData

func (tu *TransactionUtils) ProcessSwapData(transfers []types.TransferData, dexInfo types.DexInfo, skipNative bool) *types.TradeInfo

ProcessSwapData processes swap data from transfers

func (*TransactionUtils) ProcessTransferInstructions

func (tu *TransactionUtils) ProcessTransferInstructions(outerIndex int, extraTypes []string) []types.TransferData

ProcessTransferInstructions processes transfer instructions for an outer index

func (*TransactionUtils) UpdateMemeTokenInfo

func (tu *TransactionUtils) UpdateMemeTokenInfo(event *types.MemeEvent, trade *types.TradeInfo)

UpdateMemeTokenInfo updates meme event token information from trade data

Jump to

Keyboard shortcuts

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