github.com/InjectiveLabs/sdk-go@v1.53.0/chain/insurance/types/params.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "time" 6 7 "cosmossdk.io/math" 8 paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" 9 ) 10 11 var _ paramtypes.ParamSet = &Params{} 12 13 // insurance params default values 14 const ( 15 // DefaultInsurancePeriodDurationSeconds represents the number of seconds in two weeks 16 DefaultInsurancePeriod = time.Hour * 24 * 14 17 DefaultBinaryOptionsInsurancePeriod = time.Minute 18 ) 19 20 // MaxUnderwritingAmount equals 1 trillion * 1e18 21 var MaxUnderwritingAmount, _ = math.NewIntFromString("1000000000000000000000000000") 22 var PerpetualExpiryFlag int64 = -1 23 var BinaryOptionsExpiryFlag int64 = -2 24 25 // Parameter keys 26 var ( 27 KeyDefaultRedemptionNoticePeriodDuration = []byte("defaultRedemptionNoticePeriodDuration") 28 ) 29 30 // ParamKeyTable returns the parameter key table. 31 func ParamKeyTable() paramtypes.KeyTable { 32 return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) 33 } 34 35 // NewParams creates a new Params instance 36 func NewParams( 37 defaultRedemptionNoticePeriodDuration time.Duration, 38 ) Params { 39 return Params{ 40 DefaultRedemptionNoticePeriodDuration: defaultRedemptionNoticePeriodDuration, 41 } 42 } 43 44 // ParamSetPairs returns the parameter set pairs. 45 func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { 46 return paramtypes.ParamSetPairs{ 47 paramtypes.NewParamSetPair(KeyDefaultRedemptionNoticePeriodDuration, &p.DefaultRedemptionNoticePeriodDuration, validateNoticePeriodDuration), 48 } 49 } 50 51 // DefaultParams returns a default set of parameters. 52 func DefaultParams() Params { 53 return Params{ 54 DefaultRedemptionNoticePeriodDuration: DefaultInsurancePeriod, 55 } 56 } 57 58 // Validate performs basic validation on insurance parameters. 59 func (p Params) Validate() error { 60 if err := validateNoticePeriodDuration(p.DefaultRedemptionNoticePeriodDuration); err != nil { 61 return err 62 } 63 64 return nil 65 } 66 67 func validateNoticePeriodDuration(i interface{}) error { 68 v, ok := i.(time.Duration) 69 if !ok { 70 return fmt.Errorf("invalid parameter type: %T", i) 71 } 72 73 if v == 0 { 74 return fmt.Errorf("DefaultRedemptionNoticePeriodDuration must be positive: %d", v) 75 } 76 77 return nil 78 }