laconicd/x/auction/params.go
Prathamesh Musale c162396298
All checks were successful
Integration Tests / test-integration (push) Successful in 2m43s
Unit Tests / test-unit (push) Successful in 3m27s
E2E Tests / test-e2e (push) Successful in 2m48s
SDK Tests / sdk_tests_nameservice_expiry (push) Successful in 7m57s
SDK Tests / sdk_tests (push) Successful in 8m59s
SDK Tests / sdk_tests_auctions (push) Successful in 13m4s
Change token denom from photon to lnt and alnt (#46)
Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675)

Co-authored-by: zramsay <zach@bluecollarcoding.ca>
Reviewed-on: #46
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-07-30 11:05:58 +00:00

144 lines
3.3 KiB
Go

package auction
import (
"errors"
fmt "fmt"
"strings"
time "time"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
DefaultCommitsDuration = 5 * time.Minute
DefaultRevealsDuration = 5 * time.Minute
DefaultCommitFee = sdkmath.NewInt(1000) // 10^3 alnt
DefaultRevealFee = sdkmath.NewInt(1000) // 10^3 alnt
DefaultMinimumBid = sdkmath.NewInt(1000000) // 10^6 alnt
)
func NewParams(commitsDuration time.Duration, revealsDuration time.Duration, commitFee sdk.Coin, revealFee sdk.Coin, minimumBid sdk.Coin) Params {
return Params{
CommitsDuration: commitsDuration,
RevealsDuration: revealsDuration,
CommitFee: commitFee,
RevealFee: revealFee,
MinimumBid: minimumBid,
}
}
// DefaultParams returns a default set of parameters.
func DefaultParams() Params {
return Params{
CommitsDuration: DefaultCommitsDuration,
RevealsDuration: DefaultRevealsDuration,
CommitFee: sdk.NewCoin(sdk.DefaultBondDenom, DefaultCommitFee),
RevealFee: sdk.NewCoin(sdk.DefaultBondDenom, DefaultRevealFee),
MinimumBid: sdk.NewCoin(sdk.DefaultBondDenom, DefaultMinimumBid),
}
}
// String returns a human readable string representation of the parameters.
func (p Params) String() string {
var sb strings.Builder
sb.WriteString("Params: \n")
sb.WriteString(fmt.Sprintf("CommitsDuration: %s\n", p.CommitsDuration.String()))
sb.WriteString(fmt.Sprintf("RevealsDuration: %s\n", p.RevealsDuration.String()))
sb.WriteString(fmt.Sprintf("CommitFee: %s\n", p.CommitFee.String()))
sb.WriteString(fmt.Sprintf("RevealFee: %s\n", p.RevealFee.String()))
sb.WriteString(fmt.Sprintf("MinimumBid: %s\n", p.MinimumBid.String()))
return sb.String()
}
// Validate a set of params.
func (p Params) Validate() error {
if err := validateCommitsDuration(p.CommitsDuration); err != nil {
return err
}
if err := validateRevealsDuration(p.RevealsDuration); err != nil {
return err
}
if err := validateCommitFee(p.CommitFee); err != nil {
return err
}
if err := validateRevealFee(p.RevealFee); err != nil {
return err
}
if err := validateMinimumBid(p.MinimumBid); err != nil {
return err
}
return nil
}
func validateCommitsDuration(i interface{}) error {
v, ok := i.(time.Duration)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v < 0 {
return errors.New("commits duration cannot be negative")
}
return nil
}
func validateRevealsDuration(i interface{}) error {
v, ok := i.(time.Duration)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v < 0 {
return errors.New("reveals duration cannot be negative")
}
return nil
}
func validateCommitFee(i interface{}) error {
v, ok := i.(sdk.Coin)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.Amount.IsNegative() {
return errors.New("commit fee must be positive")
}
return nil
}
func validateRevealFee(i interface{}) error {
v, ok := i.(sdk.Coin)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.Amount.IsNegative() {
return errors.New("reveal fee must be positive")
}
return nil
}
func validateMinimumBid(i interface{}) error {
v, ok := i.(sdk.Coin)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.Amount.IsNegative() {
return errors.New("minimum bid must be positive")
}
return nil
}