coin

package
v6.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UTokenPrefix defines the uToken denomination prefix for all uToken types.
	UTokenPrefix = "u/"
)

Variables

View Source
var (
	// the uToken denom "u/uumee"
	UumeeDenom = ToUTokenDenom(umee)
	// 1uumee Coin
	Umee1 = New(umee, 1)
	// 10_000uumee Coin
	Umee10k = New(umee, 10_000)
	// 1u/uumee Coin
	UUmee1 = Utoken(umee, 1)

	// Xuumee DecCoin
	Umee0dec = DecF(umee, 0)
	Umee1dec = DecF(umee, 1)

	Atom = "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9"
	// 1<atom ibc denom> Coin
	Atom1 = New(Atom, 1)
	// 1u/<atom ibc denom> Coin
	UAtom1 = Utoken(Atom, 1)

	Atom1dec = DecF(Atom, 1)
	// 1.25<atom ibc denom> DecCoin
	Atom1_25dec = DecF(Atom, 1.25)

	// a test denom
	Dollar = "dollar"
)

common coins used in tests

View Source
var Exponents = map[int]sdk.Dec{
	-18: sdk.MustNewDecFromStr("0.000000000000000001"),
	-17: sdk.MustNewDecFromStr("0.00000000000000001"),
	-16: sdk.MustNewDecFromStr("0.0000000000000001"),
	-15: sdk.MustNewDecFromStr("0.000000000000001"),
	-14: sdk.MustNewDecFromStr("0.00000000000001"),
	-13: sdk.MustNewDecFromStr("0.0000000000001"),
	-12: sdk.MustNewDecFromStr("0.000000000001"),
	-11: sdk.MustNewDecFromStr("0.00000000001"),
	-10: sdk.MustNewDecFromStr("0.0000000001"),
	-9:  sdk.MustNewDecFromStr("0.000000001"),
	-8:  sdk.MustNewDecFromStr("0.00000001"),
	-7:  sdk.MustNewDecFromStr("0.0000001"),
	-6:  sdk.MustNewDecFromStr("0.000001"),
	-5:  sdk.MustNewDecFromStr("0.00001"),
	-4:  sdk.MustNewDecFromStr("0.0001"),
	-3:  sdk.MustNewDecFromStr("0.001"),
	-2:  sdk.MustNewDecFromStr("0.01"),
	-1:  sdk.MustNewDecFromStr("0.1"),
	0:   sdk.MustNewDecFromStr("1.0"),
	1:   sdk.MustNewDecFromStr("10.0"),
	2:   sdk.MustNewDecFromStr("100.0"),
	3:   sdk.MustNewDecFromStr("1000.0"),
	4:   sdk.MustNewDecFromStr("10000.0"),
	5:   sdk.MustNewDecFromStr("100000.0"),
	6:   sdk.MustNewDecFromStr("1000000.0"),
	7:   sdk.MustNewDecFromStr("10000000.0"),
	8:   sdk.MustNewDecFromStr("100000000.0"),
	9:   sdk.MustNewDecFromStr("1000000000.0"),
	10:  sdk.MustNewDecFromStr("10000000000.0"),
	11:  sdk.MustNewDecFromStr("100000000000.0"),
	12:  sdk.MustNewDecFromStr("1000000000000.0"),
	13:  sdk.MustNewDecFromStr("10000000000000.0"),
	14:  sdk.MustNewDecFromStr("100000000000000.0"),
	15:  sdk.MustNewDecFromStr("1000000000000000.0"),
	16:  sdk.MustNewDecFromStr("10000000000000000.0"),
	17:  sdk.MustNewDecFromStr("100000000000000000.0"),
	18:  sdk.MustNewDecFromStr("1000000000000000000.0"),
}

Functions

func Dec

func Dec(denom, amount string) sdk.DecCoin

Dec creates a DecCoin with a given base denom and amount.

func DecF

func DecF(denom string, amount float64) sdk.DecCoin

DecF creates a DecCoin based on float amount. MUST not be used in production code. Can only be used in tests.

func HasUTokenPrefix

func HasUTokenPrefix(denom string) bool

HasUTokenPrefix detects the uToken prefix on a denom.

func Negative1

func Negative1(denom string) sdk.Coin

Negative1 creates a Coin with amount = -1

func New

func New(denom string, amount int64) sdk.Coin

New creates a Coin with a given base denom and amount

func Normalize

func Normalize(cs sdk.Coins) sdk.Coins

Normalize transform nil coins to empty list

func One added in v6.3.0

func One(denom string) sdk.Coin

One returns new coin with one amount

func StripUTokenDenom

func StripUTokenDenom(denom string) string

StripUTokenDenom strips the uToken prefix from a denom, or returns an empty string if it was not present. Also returns an empty string if the prefix was repeated multiple times.

func ToUTokenDenom

func ToUTokenDenom(denom string) string

ToUTokenDenom adds the uToken prefix to a denom. Returns an empty string instead if the prefix was already present.

func UmeeCoins

func UmeeCoins(amount int64) sdk.Coins

UmeeCoins creates an Umee (uumee) sdk.Coins with given amount

func UmeeDec

func UmeeDec(amount string) sdk.DecCoin

UmeeDec creates a Umee (uumee) DecCoin with given amount

func Utoken

func Utoken(denom string, amount int64) sdk.Coin

Utoken creates a uToken Coin.

func UtokenDec

func UtokenDec(denom string, amount string) sdk.DecCoin

UtokenDec creates a uToken DecCoin.

func UtokenDecF

func UtokenDecF(denom string, amount float64) sdk.DecCoin

UtokenDecF creates a uToken DecCoin.

func Zero

func Zero(denom string) sdk.Coin

Zero returns new coin with zero amount

func ZeroDec

func ZeroDec(denom string) sdk.DecCoin

ZeroDec returns new decCoin with zero amount

Types

type DecBld

type DecBld struct {
	D sdk.DecCoin
}

TODO: add unit tests for `util/coin/math.go` DecBld is a Builder pattern for dec coin

func NewDecBld

func NewDecBld(d sdk.DecCoin) *DecBld

NewDecBld is a constructor for DecBld type

func (*DecBld) Scale

func (d *DecBld) Scale(f int64) *DecBld

Scale scales dec coin by given factor

func (*DecBld) ScaleStr

func (d *DecBld) ScaleStr(f string) *DecBld

Scale scales dec coin by given factor provided as string. Panics if f is not a correct decimal number.

func (*DecBld) ToCoin

func (d *DecBld) ToCoin() sdk.Coin

ToCoin converts DecCoin to sdk.Coin rounding up

func (*DecBld) ToCoins

func (d *DecBld) ToCoins() sdk.Coins

ToCoins converts DecCoin to sdk.Coins rounding up

func (*DecBld) ToDecCoins

func (d *DecBld) ToDecCoins() sdk.DecCoins

ToCoin converts DecCoin to sdk.DecCoins

Jump to

Keyboard shortcuts

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