Skip to content

Commit

Permalink
fix: improve/fix parameter validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fragwuerdig authored Oct 16, 2023
1 parent 17541c7 commit d868d4b
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions x/dyncomm/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,42 @@ func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {

// Validate a set of params
func (p Params) Validate() error {
if !p.SlopeBase.IsPositive() {
return fmt.Errorf("mint base pool should be positive or zero, is %s", p.SlopeBase)
if p.SlopeBase.IsNegative() {
return fmt.Errorf("Slope Base must be positive or zero, is %s", p.SlopeBase)
}
if !p.SlopeVpImpact.IsPositive() {
return fmt.Errorf("pool recovery period should be positive, is %d", p.SlopeVpImpact)
return fmt.Errorf("Solpe VP impact should be positive, is %d", p.SlopeVpImpact)

This comment has been minimized.

Copy link
@StrathCole

StrathCole Oct 17, 2023

Collaborator

Typo.

Solpe / Slope

}
if p.Cap.IsNegative() {
return fmt.Errorf("cap shall be 0 or positive: %s", p.Cap)
}
if p.Cap.GT(sdk.OneDec()) {
return fmt.Errorf("cap shall be less than 1.0: %s", p.Cap)
}
if p.MaxZero.IsNegative() {
return fmt.Errorf("max zero shall be 0 or positive: %s", v)

Check failure on line 77 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: v

Check failure on line 77 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: v

Check failure on line 77 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: v

Check failure on line 77 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / build

undefined: v

Check failure on line 77 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / Analyze

undefined: v

Check failure on line 77 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / run-tests

undefined: v
}
if p.MaxZero.GT(sdk.OneDec()) {
return fmt.Errorf("max zero shall be less than 1.0: %s", v)

Check failure on line 80 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: v (typecheck)

Check failure on line 80 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: v) (typecheck)

Check failure on line 80 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: v) (typecheck)

Check failure on line 80 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / build

undefined: v

Check failure on line 80 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / Analyze

undefined: v

Check failure on line 80 in x/dyncomm/types/params.go

View workflow job for this annotation

GitHub Actions / run-tests

undefined: v
}

return nil
}

//f(VP) = max(min((VP - A) * (B + (VP/C)), D), min_commission)

func validateMaxZero(i interface{}) error {
_, ok := i.(sdk.Dec)
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNegative() {
return fmt.Errorf("max zero shall be 0 or positive: %s", v)
}

if v.GT(sdk.OneDec()) {
return fmt.Errorf("max zero shall be less than 1.0: %s", v)
}

return nil
}

Expand All @@ -94,8 +106,8 @@ func validateSlopeBase(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}

if !v.IsPositive() {
return fmt.Errorf("slope base must be positive: %s", v)
if v.IsNegative() {
return fmt.Errorf("slope base must be positive or Zero: %s", v)
}

return nil
Expand Down

0 comments on commit d868d4b

Please sign in to comment.