-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feeTiers to dex params; only allow legal feeTier deposits
- Loading branch information
Julian Compagni Portis
committed
Sep 19, 2023
1 parent
49b2019
commit 3dd750c
Showing
17 changed files
with
355 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,67 @@ | ||
package types | ||
|
||
import ( | ||
fmt "fmt" | ||
|
||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
var _ paramtypes.ParamSet = (*Params)(nil) | ||
|
||
var ( | ||
KeyFeeTiers = []byte("FeeTiers") | ||
DefaultFeeTiers []uint64 = []uint64{0, 1, 2, 3, 4, 5, 10, 20, 50, 100, 150, 200} | ||
) | ||
|
||
// ParamKeyTable the param key table for launch module | ||
func ParamKeyTable() paramtypes.KeyTable { | ||
return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) | ||
} | ||
|
||
// NewParams creates a new Params instance | ||
func NewParams() *Params { | ||
return &Params{} | ||
func NewParams(feeTiers []uint64) Params { | ||
return Params{FeeTiers: feeTiers} | ||
} | ||
|
||
// DefaultParams returns a default set of parameters | ||
func DefaultParams() *Params { | ||
return NewParams() | ||
func DefaultParams() Params { | ||
return NewParams(DefaultFeeTiers) | ||
} | ||
|
||
// ParamSetPairs get the params.ParamSet | ||
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { | ||
return paramtypes.ParamSetPairs{} | ||
return paramtypes.ParamSetPairs{ | ||
paramtypes.NewParamSetPair(KeyFeeTiers, &p.FeeTiers, validateFeeTiers), | ||
} | ||
} | ||
|
||
// String implements the Stringer interface. | ||
func (p Params) String() string { | ||
out, _ := yaml.Marshal(p) | ||
return string(out) | ||
} | ||
|
||
// Validate validates the set of params | ||
func (p Params) Validate() error { | ||
if err := validateFeeTiers(p.FeeTiers); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// String implements the Stringer interface. | ||
func (p Params) String() string { | ||
out, _ := yaml.Marshal(p) | ||
return string(out) | ||
func validateFeeTiers(v interface{}) error { | ||
feeTiers, ok := v.([]uint64) | ||
if !ok { | ||
return fmt.Errorf("invalid parameter type: %T", v) | ||
} | ||
|
||
feeTierMap := make(map[uint64]bool) | ||
for _, f := range feeTiers { | ||
if _, ok := feeTierMap[f]; ok { | ||
return fmt.Errorf("duplicate fee tier found") | ||
} | ||
feeTierMap[f] = true | ||
} | ||
return nil | ||
} |
Oops, something went wrong.