currency

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 31 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// BuyFeeBps is the fee charged when buying a launchpad currency with the
	// core mint, which mirrors currencycreator.DefaultSellFeeBps.
	BuyFeeBps = currencycreator.DefaultSellFeeBps

	// FeeQuarkTolerance is the maximum difference allowed between a client
	// provided fee amount and the server computed value. It absorbs rounding
	// differences between client and server.
	FeeQuarkTolerance = 1
)
View Source
const (
	MaxDailyUsdLimit = 1_000.00
)

Variables

View Source
var (
	SendLimits = map[currency_lib.Code]SendLimit{}/* 163 elements not displayed */

)

todo: Better way of managing all of this

Functions

func ApplySellFee added in v1.23.0

func ApplySellFee(value float64) float64

ApplySellFee returns the value remaining after the launchpad sell fee.

func CalculateExchangeRate added in v0.22.0

func CalculateExchangeRate(mintAccount *common.Account, quarks uint64, nativeAmount float64) float64

CalculateExchangeRate calculates the exchange rate for a crypto value exchange.

func CalculateMarketCap added in v1.3.0

func CalculateMarketCap(supplyFromBonding uint64, exchangeRate float64) float64

CalculateMarketCap calculates the market cap for a currency creator mint. Market cap = price per token × circulating supply.

func CalculateUsdMarketValueFromFiatAmount added in v0.24.0

func CalculateUsdMarketValueFromFiatAmount(fiatAmount, fiatToUsdRate float64) (float64, error)

CalculateUsdMarketValueFromFiatAmount calculates the USD market value for a given fiat value and exchange rate.

func CalculateUsdMarketValueFromTokenAmount added in v0.24.0

func CalculateUsdMarketValueFromTokenAmount(ctx context.Context, data ocp_data.Provider, exchangeRateStore exchange.Store, reserveStore reserve.Store, mint *common.Account, quarks uint64, at time.Time) (float64, error)

CalculateUsdMarketValueFromTokenAmount calculates the current USD market value of a crypto amount in quarks.

func DiscountValueForBuyFee added in v1.23.0

func DiscountValueForBuyFee(value float64, swapAmount, feeAmount uint64) float64

DiscountValueForBuyFee scales a value quoted over the full amount funding a swap (swap plus fee) down to the portion that was actually swapped.

func ExpectedBuyFeeQuarks added in v1.23.0

func ExpectedBuyFeeQuarks(swapAmount uint64) uint64

ExpectedBuyFeeQuarks returns the fee in quarks charged on a buy of the provided quark amount.

func GetLaunchpadCurrencyCirculatingSupply added in v0.21.0

func GetLaunchpadCurrencyCirculatingSupply(ctx context.Context, data ocp_data.Provider, mint *common.Account) (uint64, uint64, time.Time, error)

GetLaunchpadCurrencyCirculatingSupply gets the current circulating supply in quarks for a launchpad currency directly from the blockchain

func GrossUpSellFee added in v1.23.0

func GrossUpSellFee(value float64) float64

GrossUpSellFee returns the value prior to the launchpad sell fee being taken, which is the inverse of ApplySellFee.

func IsExpectedFeeQuarks added in v1.23.0

func IsExpectedFeeQuarks(actual, expected uint64) bool

IsExpectedFeeQuarks returns whether a client provided fee amount matches the server computed value within FeeQuarkTolerance.

func SetHolderMetrics added in v1.4.0

func SetHolderMetrics(protoMint *currencypb.Mint, holderData *LiveHolderCountData)

SetHolderMetrics applies holder count data to a proto Mint without fetching from the provider.

func SetLaunchpadReserveData added in v1.4.0

func SetLaunchpadReserveData(protoMint *currencypb.Mint, reserveState *LiveReserveStateData)

SetLaunchpadReserveData applies reserve state data to a proto Mint's LaunchpadMetadata without fetching from the provider.

func SetMarketCapMetrics added in v1.23.0

func SetMarketCapMetrics(protoMint *currencypb.Mint, marketCapData *LiveMarketCapData)

SetMarketCapMetrics applies market cap data to a proto Mint without fetching from the provider.

func ValidateClientExchangeData

func ValidateClientExchangeData(proto *transactionpb.VerifiedExchangeData) (bool, string)

ValidateClientExchangeData validates client-provided exchange data with provable exchange rates and reserve states that were provided by server.

func ValidateClientUsdFeeValue added in v1.21.0

func ValidateClientUsdFeeValue(
	mint *common.Account,
	quarks uint64,
	expectedUsdValue float64,
	clientReserveState *currencypb.VerifiedLaunchpadCurrencyReserveState,
) (bool, string)

ValidateClientUsdFeeValue validates that a quark amount of a mint is valued at the expected USD amount for a fee.

func ValidateVerifiedExchangeRate added in v0.22.0

func ValidateVerifiedExchangeRate(proto *currencypb.VerifiedCoreMintFiatExchangeRate) (bool, string)

ValidateVerifiedExchangeRate validates a server-signed exchange rate provided by a client. It verifies that the signature is valid and that the timestamp is not too far in the past.

func ValidateVerifiedReserveState added in v0.22.0

func ValidateVerifiedReserveState(proto *currencypb.VerifiedLaunchpadCurrencyReserveState) (bool, string)

ValidateVerifiedReserveState validates a server-signed reserve state provided by a client. It verifies that the signature is valid and that the timestamp is not too far in the past.

Types

type LiveExchangeRateData added in v1.3.0

type LiveExchangeRateData struct {
	Rates       map[string]float64
	SignedRates []*currencypb.VerifiedCoreMintFiatExchangeRate
}

LiveExchangeRateData represents live exchange rate data with its pre-signed response

type LiveHolderCountData added in v1.4.0

type LiveHolderCountData struct {
	Mint           *common.Account
	CurrentHolders uint64
	LastWeekDelta  int64
}

LiveHolderCountData represents live holder count data for a currency

type LiveMarketCapData added in v1.23.0

type LiveMarketCapData struct {
	Mint             *common.Account
	CurrentMarketCap float64
	LastWeekDelta    float64
}

LiveMarketCapData represents live market cap data for a currency

type LiveMintDataStream added in v1.3.0

type LiveMintDataStream struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*LiveMintDataStream) GetUpdateChannel added in v1.3.0

func (s *LiveMintDataStream) GetUpdateChannel() chan *StreamUpdate

func (*LiveMintDataStream) WantsExchangeRates added in v1.3.0

func (s *LiveMintDataStream) WantsExchangeRates() bool

func (*LiveMintDataStream) WantsMint added in v1.3.0

func (s *LiveMintDataStream) WantsMint(mint string) bool

type LiveReserveStateData added in v1.3.0

type LiveReserveStateData struct {
	Mint              *common.Account
	SupplyFromBonding uint64
	SignedState       *currencypb.VerifiedLaunchpadCurrencyReserveState
}

LiveReserveStateData represents live launchpad currency reserve state with its pre-signed response

type MintDataProvider added in v1.3.0

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

func NewMintDataProvider added in v1.3.0

func NewMintDataProvider(
	log *zap.Logger,
	data ocp_data.Provider,
	exchangeRateStore exchange.Store,
	reserveStore reserve.Store,
	holderStore holder.Store,
	protoMintCacheTTL,
	exchangeRatePollInterval,
	launchpadCurrencyPollInterval time.Duration,
) *MintDataProvider

func (*MintDataProvider) GetAllCachedCurrencyMetadata added in v1.5.0

func (m *MintDataProvider) GetAllCachedCurrencyMetadata(ctx context.Context) (map[string]*currency.MetadataRecord, error)

GetAllCachedCurrencyMetadata returns a snapshot of all currently cached currency metadata records keyed by mint address. It blocks until the first successful poll has completed.

func (*MintDataProvider) GetAllCachedHolderCounts added in v1.4.0

func (m *MintDataProvider) GetAllCachedHolderCounts(ctx context.Context) (map[string]*LiveHolderCountData, error)

GetAllCachedHolderCounts returns a snapshot of all currently cached holder counts keyed by mint address. It blocks until the first successful poll has completed.

func (*MintDataProvider) GetAllCachedMarketCaps added in v1.23.0

func (m *MintDataProvider) GetAllCachedMarketCaps(ctx context.Context) (map[string]*LiveMarketCapData, error)

GetAllCachedMarketCaps returns a snapshot of all currently cached market cap data keyed by mint address. It blocks until the first successful poll has completed.

func (*MintDataProvider) GetAllCachedReserveStates added in v1.4.0

func (m *MintDataProvider) GetAllCachedReserveStates(ctx context.Context) (map[string]*LiveReserveStateData, error)

GetAllCachedReserveStates returns a snapshot of all currently cached reserve states keyed by mint address. It blocks until the first successful poll has completed.

func (*MintDataProvider) GetExchangeRateHistory added in v1.19.0

func (m *MintDataProvider) GetExchangeRateHistory(ctx context.Context, symbol string, interval query.Interval, start, end time.Time, ordering query.Ordering) ([]*currency.ExchangeRateRecord, error)

GetExchangeRateHistory returns historical exchange rate records for the core mint, passing straight through to the underlying exchange rate store.

func (*MintDataProvider) GetLiveExchangeRates added in v1.3.0

func (m *MintDataProvider) GetLiveExchangeRates(ctx context.Context) (*LiveExchangeRateData, error)

GetLiveExchangeRates returns the current pre-signed live exchange rate data

func (*MintDataProvider) GetLiveHolderCount added in v1.4.0

func (m *MintDataProvider) GetLiveHolderCount(ctx context.Context, mint *common.Account) (*LiveHolderCountData, error)

GetLiveHolderCount returns live holder count data for a mint, blocking until the poller has retrieved it.

func (*MintDataProvider) GetLiveMarketCap added in v1.23.0

func (m *MintDataProvider) GetLiveMarketCap(ctx context.Context, mint *common.Account) (*LiveMarketCapData, error)

GetLiveMarketCap returns live market cap data for a mint, blocking until the reserve poller has retrieved the state it's derived from.

func (*MintDataProvider) GetLiveReserveState added in v1.3.0

func (m *MintDataProvider) GetLiveReserveState(ctx context.Context, mint *common.Account) (*LiveReserveStateData, error)

GetLiveReserveState returns a current pre-signed live launchpad currency reserve state for a mint

func (*MintDataProvider) GetProtoMint added in v1.3.0

func (m *MintDataProvider) GetProtoMint(ctx context.Context, mint *common.Account) (*currencypb.Mint, error)

GetProtoMint gets a proto Mint object. Static and infrequently updated metadata is heavily cached.

func (*MintDataProvider) GetReserveHistory added in v1.19.0

func (m *MintDataProvider) GetReserveHistory(ctx context.Context, mint string, interval query.Interval, start, end time.Time, ordering query.Ordering) ([]*currency.ReserveRecord, error)

GetReserveHistory returns historical reserve records for a currency creator mint, passing straight through to the underlying reserve store.

func (*MintDataProvider) InjectLiveHolderMetrics added in v1.4.0

func (m *MintDataProvider) InjectLiveHolderMetrics(ctx context.Context, protoMint *currencypb.Mint) error

func (*MintDataProvider) InjectLiveLaunchpadData added in v1.3.0

func (m *MintDataProvider) InjectLiveLaunchpadData(ctx context.Context, protoMint *currencypb.Mint) error

InjectLiveLaunchpadData sets the live supply, price, and market cap fields on a proto Mint's LaunchpadMetadata.

func (*MintDataProvider) InjectLiveMarketCapMetrics added in v1.23.0

func (m *MintDataProvider) InjectLiveMarketCapMetrics(ctx context.Context, protoMint *currencypb.Mint) error

func (*MintDataProvider) RegisterStream added in v1.3.0

func (m *MintDataProvider) RegisterStream(id string, mints []*common.Account) *LiveMintDataStream

RegisterStream creates and registers a new stream for the given mints. Returns nil if the worker has been stopped.

func (*MintDataProvider) Start added in v1.3.0

func (m *MintDataProvider) Start(ctx context.Context) error

Start begins the polling goroutines for exchange rates and reserve state

func (*MintDataProvider) Stop added in v1.3.0

func (m *MintDataProvider) Stop()

stop cancels the polling goroutines and closes all streams. After stop is called, no new streams can be registered.

func (*MintDataProvider) ToProtoMint added in v1.3.0

func (m *MintDataProvider) ToProtoMint(
	ctx context.Context,
	metadataRecord *currency.MetadataRecord,
	includeLiveReserveState, includeLiveHolderMetrics, includeLiveMarketCapMetrics bool,
) (*currencypb.Mint, error)

ToProtoMint converts a currency MetadataRecord into a proto Mint object with live launchpad data (supply, price, market cap) injected from the provider's cached reserve state.

func (*MintDataProvider) UnregisterStream added in v1.3.0

func (m *MintDataProvider) UnregisterStream(id string)

UnregisterStream removes a stream and closes it

type SendLimit

type SendLimit struct {
	PerTransaction float64
}

type StreamUpdate added in v1.3.0

type StreamUpdate struct {
	ExchangeRates *LiveExchangeRateData
	ReserveStates []*LiveReserveStateData
}

StreamUpdate represents an update to send to streams

Jump to

Keyboard shortcuts

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