github.com/InjectiveLabs/sdk-go@v1.53.0/chain/tokenfactory/types/params.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"cosmossdk.io/math"
     7  	sdk "github.com/cosmos/cosmos-sdk/types"
     8  	paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
     9  
    10  	chaintypes "github.com/InjectiveLabs/sdk-go/chain/types"
    11  )
    12  
    13  // Parameter store keys.
    14  var (
    15  	KeyDenomCreationFee = []byte("DenomCreationFee")
    16  )
    17  
    18  // ParamTable for gamm module.
    19  func ParamKeyTable() paramtypes.KeyTable {
    20  	return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
    21  }
    22  
    23  func NewParams(denomCreationFee sdk.Coins) Params {
    24  	return Params{
    25  		DenomCreationFee: denomCreationFee,
    26  	}
    27  }
    28  
    29  // default gamm module parameters.
    30  func DefaultParams() Params {
    31  	return Params{
    32  		DenomCreationFee: sdk.NewCoins(sdk.NewCoin(chaintypes.InjectiveCoin, math.NewIntWithDecimal(10, 18))), // 10 INJ
    33  	}
    34  }
    35  
    36  // validate params.
    37  func (p Params) Validate() error {
    38  	if err := validateDenomCreationFee(p.DenomCreationFee); err != nil {
    39  		return err
    40  	}
    41  
    42  	return nil
    43  }
    44  
    45  // Implements params.ParamSet.
    46  func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
    47  	return paramtypes.ParamSetPairs{
    48  		paramtypes.NewParamSetPair(KeyDenomCreationFee, &p.DenomCreationFee, validateDenomCreationFee),
    49  	}
    50  }
    51  
    52  func validateDenomCreationFee(i interface{}) error {
    53  	v, ok := i.(sdk.Coins)
    54  	if !ok {
    55  		return fmt.Errorf("invalid parameter type: %T", i)
    56  	}
    57  
    58  	if v.Validate() != nil {
    59  		return fmt.Errorf("invalid denom creation fee: %+v", i)
    60  	}
    61  
    62  	return nil
    63  }