github.com/lino-network/lino@v0.6.11/types/ida.go (about)

     1  package types
     2  
     3  import (
     4  	sdk "github.com/cosmos/cosmos-sdk/types"
     5  )
     6  
     7  // IDAStr - string representation of the number of IDA.
     8  // same as coin, support at most 5 digits precision(log10(Decimals)).
     9  type IDAStr string
    10  
    11  // MiniIDA is an integer.
    12  // 100000 MiniIDA =  one IDA(Decimals).
    13  type MiniIDA = sdk.Int
    14  
    15  func (i IDAStr) ToMiniIDA() (MiniIDA, sdk.Error) {
    16  	dec, err := sdk.NewDecFromStr(string(i))
    17  	if err != nil {
    18  		return sdk.NewInt(0), ErrInvalidIDAAmount()
    19  	}
    20  	if dec.GT(UpperBoundRat) {
    21  		return sdk.NewInt(0), ErrInvalidIDAAmount()
    22  	}
    23  	if dec.LT(LowerBoundRat) {
    24  		return sdk.NewInt(0), ErrInvalidIDAAmount()
    25  	}
    26  	return dec.MulInt64(Decimals).RoundInt(), nil
    27  }
    28  
    29  func MiniIDAToMiniDollar(amount MiniIDA, miniIDAPrice MiniDollar) MiniDollar {
    30  	return MiniDollar{miniIDAPrice.Mul(amount)}
    31  }