common

package
v1.10.21-0...-6a6bd8a Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 29 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CoreMintAccount, _    = NewAccountFromPublicKeyBytes(config.CoreMintPublicKeyBytes)
	CoreMintQuarksPerUnit = uint64(config.CoreMintQuarksPerUnit)
	CoreMintDecimals      = config.CoreMintDecimals
	CoreMintName          = config.CoreMintName
	CoreMintSymbol        = config.CoreMintSymbol

	ErrUnsupportedMint = errors.New("unsupported mint")
)
View Source
var (
	// The well-known Code VM instance
	CodeVmAccount, _ = NewAccountFromPublicKeyString(config.VmAccountPublicKey)

	// The well-known Code VM instance omnibus account
	CodeVmOmnibusAccount, _ = NewAccountFromPublicKeyString(config.VmOmnibusPublicKey)
)
View Source
var (
	ErrOwnerNotFound = errors.New("owner account not found")
)
View Source
var (
	ErrSubsidizerRequiresFunding = errors.New("subsidizer requires funding")
)

Functions

func EnforceMinimumSubsidizerBalance

func EnforceMinimumSubsidizerBalance(ctx context.Context, data code_data.Provider) error

EnforceMinimumSubsidizerBalance returns ErrSubsidizerRequiresFunding if the subsidizer's estimated available balance breaks a given threshold.

func EstimateUsedSubsidizerBalance

func EstimateUsedSubsidizerBalance(ctx context.Context, data code_data.Provider) (uint64, error)

EstimateUsedSubsidizerBalance estimates the number of lamports that will be used by in flight fulfillments.

todo: This assumes fees are constant, which might not be the case in the future.

func FromCoreMintQuarks

func FromCoreMintQuarks(quarks uint64) uint64

func GetCurrentSubsidizerBalance

func GetCurrentSubsidizerBalance(ctx context.Context, data code_data.Provider) (uint64, error)

GetCurrentSubsidizerBalance returns the subsidizer's current balance in lamports.

func GetLatestCodeTimelockAccountRecordsForOwner added in v1.3.0

func GetLatestCodeTimelockAccountRecordsForOwner(ctx context.Context, data code_data.Provider, owner *Account) (map[string]map[commonpb.AccountType][]*AccountRecords, error)

GetLatestCodeTimelockAccountRecordsForOwner is a utility wrapper over GetLatestTokenAccountRecordsForOwner that filters for Code Timelock accounts.

func GetLatestTokenAccountRecordsForOwner

func GetLatestTokenAccountRecordsForOwner(ctx context.Context, data code_data.Provider, owner *Account) (map[string]map[commonpb.AccountType][]*AccountRecords, error)

GetLatestTokenAccountRecordsForOwner gets DB records for the latest set of token accounts for an owner account.

func GetMintQuarksPerUnit

func GetMintQuarksPerUnit(mint *Account) uint64

func InjectTestSubsidizer

func InjectTestSubsidizer(ctx context.Context, data code_data.Provider, testAccount *Account) error

InjectTestSubsidizer injects a provided account as a subsidizer for testing purposes. Do not call this in a production setting.

func IsCoreMint

func IsCoreMint(mint *Account) bool

func IsCoreMintUsdStableCoin

func IsCoreMintUsdStableCoin() bool

func IsManagedByCode

func IsManagedByCode(ctx context.Context, timelockRecord *timelock.Record) bool

func IsSupportedMint

func IsSupportedMint(ctx context.Context, data code_data.Provider, mintAccount *Account) (bool, error)

func LoadProductionSubsidizer

func LoadProductionSubsidizer(ctx context.Context, data code_data.Provider) error

LoadProductionSubsidizer loads the production subsidizer account by it's public key over the provided data provider. This should be done exactly once on app launch. Use GetSubsidizer to get the Account struct.

func ToCoreMintQuarks

func ToCoreMintQuarks(units uint64) uint64

func ValidateExternalTokenAccount

func ValidateExternalTokenAccount(ctx context.Context, data code_data.Provider, tokenAccount, mintAccount *Account) (bool, string, error)

ValidateExternalTokenAccount validates an address is an external token account for the provided mint

Types

type Account

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

func GetBackwardsCompatMint

func GetBackwardsCompatMint(protoMint *commonpb.SolanaAccountId) (*Account, error)

func GetSubsidizer

func GetSubsidizer() *Account

GetSubsidizer gets the subsidizer account, as initially loaded in LoadSubsidizer

func GetVirtualTimelockAccountLocationInMemory

func GetVirtualTimelockAccountLocationInMemory(ctx context.Context, vmIndexerClient indexerpb.IndexerClient, vm, owner *Account) (*Account, uint16, error)

func NewAccountFromPrivateKey

func NewAccountFromPrivateKey(privateKey *Key) (*Account, error)

func NewAccountFromPrivateKeyBytes

func NewAccountFromPrivateKeyBytes(publicKey []byte) (*Account, error)

func NewAccountFromPrivateKeyString

func NewAccountFromPrivateKeyString(privateKey string) (*Account, error)

func NewAccountFromProto

func NewAccountFromProto(proto *commonpb.SolanaAccountId) (*Account, error)

func NewAccountFromPublicKey

func NewAccountFromPublicKey(publicKey *Key) (*Account, error)

func NewAccountFromPublicKeyBytes

func NewAccountFromPublicKeyBytes(publicKey []byte) (*Account, error)

func NewAccountFromPublicKeyString

func NewAccountFromPublicKeyString(publicKey string) (*Account, error)

func NewRandomAccount

func NewRandomAccount() (*Account, error)

func (*Account) GetTimelockAccounts

func (a *Account) GetTimelockAccounts(vmConfig *VmConfig) (*TimelockAccounts, error)

func (*Account) GetVmDepositAccounts

func (a *Account) GetVmDepositAccounts(vmConfig *VmConfig) (*VmDepositAccounts, error)

func (*Account) GetVmSwapAccounts

func (a *Account) GetVmSwapAccounts(vmConfig *VmConfig) (*VmSwapAccounts, error)

func (*Account) IsManagedByCode

func (a *Account) IsManagedByCode(ctx context.Context, data code_data.Provider) (bool, error)

func (*Account) IsOnCurve

func (a *Account) IsOnCurve() bool

func (*Account) PrivateKey

func (a *Account) PrivateKey() *Key

func (*Account) PublicKey

func (a *Account) PublicKey() *Key

func (*Account) Sign

func (a *Account) Sign(message []byte) ([]byte, error)

func (*Account) String

func (a *Account) String() string

func (*Account) ToAssociatedTokenAccount

func (a *Account) ToAssociatedTokenAccount(mint *Account) (*Account, error)

func (*Account) ToProto

func (a *Account) ToProto() *commonpb.SolanaAccountId

func (*Account) ToTimelockVault

func (a *Account) ToTimelockVault(vmConfig *VmConfig) (*Account, error)

func (*Account) ToVmDepositAta

func (a *Account) ToVmDepositAta(vmConfig *VmConfig) (*Account, error)

func (*Account) ToVmSwapAta

func (a *Account) ToVmSwapAta(vmConfig *VmConfig) (*Account, error)

func (*Account) Validate

func (a *Account) Validate() error

type AccountRecords

type AccountRecords struct {
	General  *account.Record
	Timelock *timelock.Record
}

func (*AccountRecords) IsManagedByCode

func (r *AccountRecords) IsManagedByCode(ctx context.Context) bool

func (*AccountRecords) IsTimelock added in v1.3.0

func (r *AccountRecords) IsTimelock() bool

type Key

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

func NewKeyFromBytes

func NewKeyFromBytes(value []byte) (*Key, error)

func NewKeyFromString

func NewKeyFromString(value string) (*Key, error)

func NewRandomKey

func NewRandomKey() (*Key, error)

func (*Key) IsPublic

func (k *Key) IsPublic() bool

func (*Key) ToBase58

func (k *Key) ToBase58() string

func (*Key) ToBytes

func (k *Key) ToBytes() []byte

func (*Key) Validate

func (k *Key) Validate() error

type LaunchpadCurrencyAccounts

type LaunchpadCurrencyAccounts struct {
	Mint               *Account
	CurrencyConfig     *Account
	CurrencyConfigBump uint8
	LiquidityPool      *Account
	LiquidityPoolBump  uint8
	VaultBase          *Account
	VaultBaseBump      uint8
	VaultMint          *Account
	VaultMintBump      uint8
	FeesBase           *Account
	FeesMint           *Account
}

func GetLaunchpadCurrencyAccounts

func GetLaunchpadCurrencyAccounts(metadataRecord *currency.MetadataRecord) (*LaunchpadCurrencyAccounts, error)

type OwnerManagementState

type OwnerManagementState uint8
const (
	OwnerManagementStateUnknown OwnerManagementState = iota
	OwnerManagementStateCodeAccount
	OwnerManagementStateNotFound
	OwnerManagementStateUnlocked
)

func GetOwnerManagementState

func GetOwnerManagementState(ctx context.Context, data code_data.Provider, owner *Account) (OwnerManagementState, error)

GetOwnerManagementState returns an aggregate management state for an owner account based on the set of sub accounts it owns.

todo: Needs tests here, but most already exist in account service

func (OwnerManagementState) String

func (t OwnerManagementState) String() string

type OwnerMetadata

type OwnerMetadata struct {
	Type    OwnerType
	Account *Account
	State   OwnerManagementState
}

func GetOwnerMetadata

func GetOwnerMetadata(ctx context.Context, data code_data.Provider, owner *Account) (*OwnerMetadata, error)

GetOwnerMetadata gets metadata about an owner account

todo: assumes the core mint accounts are always opened first

type OwnerType

type OwnerType uint8
const (
	OwnerTypeUnknown OwnerType = iota
	OwnerTypeUser12Words
	OwnerTypeRemoteSendGiftCard
)

func (OwnerType) String

func (t OwnerType) String() string

type TimelockAccounts

type TimelockAccounts struct {
	VaultOwner *Account

	State     *Account
	StateBump uint8

	Vault     *Account
	VaultBump uint8

	Unlock     *Account
	UnlockBump uint8

	VmDepositAccounts *VmDepositAccounts
	VmSwapAccounts    *VmSwapAccounts

	Vm   *Account
	Mint *Account
}

func (*TimelockAccounts) GetDBRecord

func (a *TimelockAccounts) GetDBRecord(ctx context.Context, data code_data.Provider) (*timelock.Record, error)

GetDBRecord fetches the equivalent timelock.Record for a TimelockAccounts from the DB

func (*TimelockAccounts) GetInitializeInstruction

func (a *TimelockAccounts) GetInitializeInstruction(vmAuthority, memory *Account, accountIndex uint16) (solana.Instruction, error)

GetInitializeInstruction gets a SystemTimelockInitInstruction instruction for a Timelock account

func (*TimelockAccounts) ToDBRecord

func (a *TimelockAccounts) ToDBRecord() *timelock.Record

ToDBRecord transforms the TimelockAccounts struct to a default timelock.Record

type VmConfig

type VmConfig struct {
	Authority *Account
	Vm        *Account
	Omnibus   *Account
	Mint      *Account
}

func GetVmConfigForMint

func GetVmConfigForMint(ctx context.Context, data code_data.Provider, mint *Account) (*VmConfig, error)

type VmDepositAccounts

type VmDepositAccounts struct {
	VaultOwner *Account

	Pda     *Account
	PdaBump uint8

	Ata *Account

	Vm   *Account
	Mint *Account
}

type VmSwapAccounts

type VmSwapAccounts struct {
	VaultOwner *Account

	Pda     *Account
	PdaBump uint8

	Ata *Account

	Vm   *Account
	Mint *Account
}

Jump to

Keyboard shortcuts

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