currency

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

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 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, mint *common.Account, quarks uint64, at time.Time) (float64, error)

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

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 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 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 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,
	protoMintCacheTTL,
	exchangeRatePollInterval,
	reserveStatePollInterval time.Duration,
) *MintDataProvider

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) 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) 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) 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) (*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