currencycreator

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMintMaxTokenSupply = 21_000_000 // 21mm tokens
	DefaultMintQuarksPerUnit  = 10_000_000_000
	DefaultMintMaxQuarkSupply = DefaultMintMaxTokenSupply * DefaultMintQuarksPerUnit // 21mm tokens with 10 decimals
	DefaultMintDecimals       = 10
)
View Source
const (
	MaxCurrencyConfigAccountNameLength   = 32
	MaxCurrencyConfigAccountSymbolLength = 8
)
View Source
const (
	// DefaultCurveDecimals is the number of decimal places supported by the curve
	DefaultCurveDecimals = 18

	// DiscretePricingStepSize is the token supply interval between price steps
	DiscretePricingStepSize = 100

	// DiscretePriceDecimals is the number of decimal places for scaled prices (18 decimals)
	DiscretePriceDecimals = DefaultCurveDecimals
)
View Source
const (
	BurnFeesInstructionArgsSize = 0
)
View Source
const (
	BuyAndDepositIntoVmInstructionArgsSize = (8 +
		8 +
		2) // account_index
)
View Source
const (
	BuyTokensInstructionArgsSize = (8 +
		8) // min_amount_out
)
View Source
const (
	CurrencyConfigAccountSize = (8 +
		32 +
		32 +
		MaxCurrencyConfigAccountNameLength +
		MaxCurrencyConfigAccountSymbolLength +
		32 +
		1 +
		1 +
		6) // padding
)
View Source
const (
	DefaultSellFeeBps = 100 // 1% fee
)
View Source
const (
	InitializeCurrencyInstructionArgsSize = (MaxCurrencyConfigAccountNameLength +
		MaxCurrencyConfigAccountSymbolLength +
		32 +
		1 +
		1 +
		6) // padding
)
View Source
const (
	InitializeMetadataInstructionArgsSize = 0
)
View Source
const (
	InitializePoolInstructionArgsSize = (2 +
		1 +
		1 +
		1 +
		1) // padding
)
View Source
const (
	LiquidityPoolAccountSize = (8 +
		32 +
		32 +
		32 +
		32 +
		32 +
		32 +
		8 +
		2 +
		1 +
		1 +
		1 +
		3) // padding
)
View Source
const (
	SellAndDepositIntoVmInstructionArgsSize = (8 +
		8 +
		2) // account_index
)
View Source
const (
	SellTokensInstructionArgsSize = (8 +
		8) // min_amount_out
)

Variables

View Source
var (
	MintPrefix     = []byte("mint")
	CurrencyPrefix = []byte("currency")
	PoolPrefix     = []byte("pool")
	TreasuryPrefix = []byte("treasury")
	MetadataPrefix = []byte("metadata")
)
View Source
var (
	ErrInvalidProgram         = errors.New("invalid program id")
	ErrInvalidAccountData     = errors.New("unexpected account data")
	ErrInvalidInstructionData = errors.New("unexpected instruction data")
)
View Source
var (
	PROGRAM_ADDRESS = mustBase58Decode("ccJYP5gjZqcEHaphcxAZvkxCrnTVfYMjyhSYkpQtf8Z")
	PROGRAM_ID      = ed25519.PublicKey(PROGRAM_ADDRESS)
)
View Source
var (
	METADATA_PROGRAM_ID  = ed25519.PublicKey(mustBase58Decode("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"))
	SPL_TOKEN_PROGRAM_ID = ed25519.PublicKey(mustBase58Decode("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"))
	SYSTEM_PROGRAM_ID    = ed25519.PublicKey(mustBase58Decode("11111111111111111111111111111111"))

	SYSVAR_RENT_PUBKEY = ed25519.PublicKey(mustBase58Decode("SysvarRent111111111111111111111111111111111"))
)
View Source
var CurrencyConfigAccountDiscriminator = []byte{byte(AccountTypeCurrencyConfig), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
View Source
var DiscreteCumulativeValueTable = initCumulativeValueTable()

DiscreteCumulativeValueTable contains pre-computed cumulative values. Values are scaled by 10^18 (18 decimal places). Each entry represents the total cost to buy tokens from supply 0 to index * 100.

View Source
var DiscretePricingTable = initPricingTable()

DiscretePricingTable contains pre-computed prices for each supply step. Prices are scaled by 10^18 (18 decimal places). Each entry represents the price at supply = index * 100.

View Source
var LiquidityPoolAccountDiscriminator = []byte{byte(AccountTypeLiquidityPool), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

Functions

func EstimateBuy

func EstimateBuy(args *EstimateBuyArgs) uint64

func EstimateCurrentPrice

func EstimateCurrentPrice(currentSupplyInQuarks uint64) *big.Float

func EstimateSell

func EstimateSell(args *EstimateSellArgs) (uint64, uint64)

func GetCurrencyAddress

func GetCurrencyAddress(args *GetCurrencyAddressArgs) (ed25519.PublicKey, uint8, error)

func GetMetadataAddress

func GetMetadataAddress(args *GetMetadataAddressArgs) (ed25519.PublicKey, uint8, error)

func GetMintAddress

func GetMintAddress(args *GetMintAddressArgs) (ed25519.PublicKey, uint8, error)

func GetPoolAddress

func GetPoolAddress(args *GetPoolAddressArgs) (ed25519.PublicKey, uint8, error)

func GetVaultAddress

func GetVaultAddress(args *GetVaultAddressArgs) (ed25519.PublicKey, uint8, error)

func NewBurnFeesInstruction added in v0.7.0

func NewBurnFeesInstruction(
	accounts *BurnFeesInstructionAccounts,
	args *BurnFeesInstructionArgs,
) solana.Instruction

func ToQuarks

func ToQuarks(amount uint64) uint64

Types

type AccountType

type AccountType uint8
const (
	AccountTypeUnknown AccountType = iota
	AccountTypeCurrencyConfig
	AccountTypeLiquidityPool
)

type BurnFeesInstructionAccounts added in v0.7.0

type BurnFeesInstructionAccounts struct {
	Payer     ed25519.PublicKey
	Pool      ed25519.PublicKey
	BaseMint  ed25519.PublicKey
	VaultBase ed25519.PublicKey
}

type BurnFeesInstructionArgs added in v0.7.0

type BurnFeesInstructionArgs struct {
}

type BuyAndDepositIntoVmInstructionAccounts

type BuyAndDepositIntoVmInstructionAccounts struct {
	Buyer       ed25519.PublicKey
	Pool        ed25519.PublicKey
	TargetMint  ed25519.PublicKey
	BaseMint    ed25519.PublicKey
	VaultTarget ed25519.PublicKey
	VaultBase   ed25519.PublicKey
	BuyerBase   ed25519.PublicKey

	VmAuthority ed25519.PublicKey
	Vm          ed25519.PublicKey
	VmMemory    ed25519.PublicKey
	VmOmnibus   ed25519.PublicKey
	VtaOwner    ed25519.PublicKey
}

type BuyAndDepositIntoVmInstructionArgs

type BuyAndDepositIntoVmInstructionArgs struct {
	InAmount      uint64
	MinOutAmount  uint64
	VmMemoryIndex uint16
}

type BuyTokensInstructionAccounts

type BuyTokensInstructionAccounts struct {
	Buyer       ed25519.PublicKey
	Pool        ed25519.PublicKey
	TargetMint  ed25519.PublicKey
	BaseMint    ed25519.PublicKey
	VaultTarget ed25519.PublicKey
	VaultBase   ed25519.PublicKey
	BuyerTarget ed25519.PublicKey
	BuyerBase   ed25519.PublicKey
}

type BuyTokensInstructionArgs

type BuyTokensInstructionArgs struct {
	InAmount     uint64
	MinAmountOut uint64
}

type CurrencyConfigAccount

type CurrencyConfigAccount struct {
	Authority ed25519.PublicKey
	Mint      ed25519.PublicKey
	Name      string
	Symbol    string
	Seed      ed25519.PublicKey
	Bump      uint8
	MintBump  uint8
}

func (*CurrencyConfigAccount) String

func (obj *CurrencyConfigAccount) String() string

func (*CurrencyConfigAccount) Unmarshal

func (obj *CurrencyConfigAccount) Unmarshal(data []byte) error

type DiscreteExponentialCurve added in v0.7.0

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

DiscreteExponentialCurve implements a discrete pricing curve using pre-computed tables. Prices are stored as scaled u128 values with 18 decimal precision.

func DefaultDiscreteExponentialCurve added in v0.7.0

func DefaultDiscreteExponentialCurve() *DiscreteExponentialCurve

DefaultDiscreteExponentialCurve creates a new default discrete exponential curve instance.

func (*DiscreteExponentialCurve) SpotPriceAtSupply added in v0.7.0

func (c *DiscreteExponentialCurve) SpotPriceAtSupply(currentSupply *big.Float) *big.Float

SpotPriceAtSupply returns the current price per token at the given supply level. Returns nil if the supply is beyond the table bounds.

func (*DiscreteExponentialCurve) TokensToValue added in v0.7.0

func (c *DiscreteExponentialCurve) TokensToValue(currentSupply, tokens *big.Float) *big.Float

TokensToValue calculates the total cost to buy `tokens` starting at `currentSupply`. This is equivalent to "How much does it cost to get X tokens?" Returns nil if the purchase would exceed table bounds. Supports fractional tokens - does not round up or down.

func (*DiscreteExponentialCurve) ValueToTokens added in v0.7.0

func (c *DiscreteExponentialCurve) ValueToTokens(currentSupply, value *big.Float) *big.Float

ValueToTokens calculates the number of tokens received for a given value starting at currentSupply. This is equivalent to "How many tokens can I get for Y value?" Returns nil if the supply is beyond table bounds. Supports fractional tokens - does not round up or down.

type EstimateBuyArgs

type EstimateBuyArgs struct {
	CurrentSupplyInQuarks uint64
	BuyAmountInQuarks     uint64
	ValueMintDecimals     uint8
}

type EstimateSellArgs

type EstimateSellArgs struct {
	CurrentSupplyInQuarks uint64
	SellAmountInQuarks    uint64
	ValueMintDecimals     uint8
	SellFeeBps            uint16
}

type GetCurrencyAddressArgs

type GetCurrencyAddressArgs struct {
	Mint ed25519.PublicKey
}

type GetMetadataAddressArgs

type GetMetadataAddressArgs struct {
	Mint ed25519.PublicKey
}

type GetMintAddressArgs

type GetMintAddressArgs struct {
	Authority ed25519.PublicKey
	Name      string
	Seed      ed25519.PublicKey
}

type GetPoolAddressArgs

type GetPoolAddressArgs struct {
	Currency ed25519.PublicKey
}

type GetVaultAddressArgs

type GetVaultAddressArgs struct {
	Pool ed25519.PublicKey
	Mint ed25519.PublicKey
}

type InitializeCurrencyInstructionAccounts

type InitializeCurrencyInstructionAccounts struct {
	Authority ed25519.PublicKey
	Mint      ed25519.PublicKey
	Currency  ed25519.PublicKey
}

type InitializeCurrencyInstructionArgs

type InitializeCurrencyInstructionArgs struct {
	Name     string
	Symbol   string
	Seed     ed25519.PublicKey
	Bump     uint8
	MintBump uint8
}

type InitializeMetadataInstructionAccounts

type InitializeMetadataInstructionAccounts struct {
	Authority ed25519.PublicKey
	Mint      ed25519.PublicKey
	Currency  ed25519.PublicKey
	Metadata  ed25519.PublicKey
}

type InitializeMetadataInstructionArgs

type InitializeMetadataInstructionArgs struct {
}

type InitializePoolInstructionAccounts

type InitializePoolInstructionAccounts struct {
	Authority   ed25519.PublicKey
	Currency    ed25519.PublicKey
	TargetMint  ed25519.PublicKey
	BaseMint    ed25519.PublicKey
	Pool        ed25519.PublicKey
	VaultTarget ed25519.PublicKey
	VaultBase   ed25519.PublicKey
}

type InitializePoolInstructionArgs

type InitializePoolInstructionArgs struct {
	SellFee         uint16
	Bump            uint8
	VaultTargetBump uint8
	VaultBaseBump   uint8
}

type InstructionType

type InstructionType uint8
const (
	Unknown InstructionType = iota

	InstructionTypeInitializeCurrency
	InstructionTypeInitializePool
	InstructionTypeInitializeMetadata

	InstructionTypeBuyTokens
	InstructionTypeSellTokens
	InstructionTypeBuyAndDepositIntoVm
	InstructionTypeSellAndDepositIntoVm
	InstructionTypeBurnFees
)

type LiquidityPoolAccount

type LiquidityPoolAccount struct {
	Authority       ed25519.PublicKey
	Currency        ed25519.PublicKey
	TargetMint      ed25519.PublicKey
	BaseMint        ed25519.PublicKey
	VaultTarget     ed25519.PublicKey
	VaultBase       ed25519.PublicKey
	FeesAccumulated uint64
	SellFee         uint16
	Bump            uint8
	VaultTargetBump uint8
	VaultBaseBump   uint8
}

func (*LiquidityPoolAccount) String

func (obj *LiquidityPoolAccount) String() string

func (*LiquidityPoolAccount) Unmarshal

func (obj *LiquidityPoolAccount) Unmarshal(data []byte) error

type SellAndDepositIntoVmInstructionAccounts

type SellAndDepositIntoVmInstructionAccounts struct {
	Seller       ed25519.PublicKey
	Pool         ed25519.PublicKey
	TargetMint   ed25519.PublicKey
	BaseMint     ed25519.PublicKey
	VaultTarget  ed25519.PublicKey
	VaultBase    ed25519.PublicKey
	SellerTarget ed25519.PublicKey

	VmAuthority ed25519.PublicKey
	Vm          ed25519.PublicKey
	VmMemory    ed25519.PublicKey
	VmOmnibus   ed25519.PublicKey
	VtaOwner    ed25519.PublicKey
}

type SellAndDepositIntoVmInstructionArgs

type SellAndDepositIntoVmInstructionArgs struct {
	InAmount      uint64
	MinOutAmount  uint64
	VmMemoryIndex uint16
}

type SellTokensInstructionAccounts

type SellTokensInstructionAccounts struct {
	Seller       ed25519.PublicKey
	Pool         ed25519.PublicKey
	TargetMint   ed25519.PublicKey
	BaseMint     ed25519.PublicKey
	VaultTarget  ed25519.PublicKey
	VaultBase    ed25519.PublicKey
	SellerTarget ed25519.PublicKey
	SellerBase   ed25519.PublicKey
}

type SellTokensInstructionArgs

type SellTokensInstructionArgs struct {
	InAmount     uint64
	MinAmountOut uint64
}

Jump to

Keyboard shortcuts

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