-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: whitelist LPs #NTRN-442 #799
base: main
Are you sure you want to change the base?
Changes from 4 commits
6c764f9
fd65529
38c713a
5c3164b
3014e0b
e8ab941
f533402
178f84b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package types | |
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
@@ -18,6 +19,8 @@ var ( | |
DefaultMaxJITsPerBlock uint64 = 25 | ||
KeyGoodTilPurgeAllowance = []byte("PurgeAllowance") | ||
DefaultGoodTilPurgeAllowance uint64 = 540_000 | ||
KeyWhitelistedLPs = []byte("PurgeAllowance") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error in key name |
||
DefaultKeyWhitelistedLPs []string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe assign an empty array to default to be more clear here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. linter does not like assigning an empty array |
||
) | ||
|
||
// ParamKeyTable the param key table for launch module | ||
|
@@ -26,18 +29,19 @@ func ParamKeyTable() paramtypes.KeyTable { | |
} | ||
|
||
// NewParams creates a new Params instance | ||
func NewParams(feeTiers []uint64, paused bool, maxJITsPerBlock, goodTilPurgeAllowance uint64) Params { | ||
func NewParams(feeTiers []uint64, paused bool, maxJITsPerBlock, goodTilPurgeAllowance uint64, whitelistedLPs []string) Params { | ||
return Params{ | ||
FeeTiers: feeTiers, | ||
Paused: paused, | ||
MaxJitsPerBlock: maxJITsPerBlock, | ||
GoodTilPurgeAllowance: goodTilPurgeAllowance, | ||
WhitelistedLps: whitelistedLPs, | ||
} | ||
} | ||
|
||
// DefaultParams returns a default set of parameters | ||
func DefaultParams() Params { | ||
return NewParams(DefaultFeeTiers, DefaultPaused, DefaultMaxJITsPerBlock, DefaultGoodTilPurgeAllowance) | ||
return NewParams(DefaultFeeTiers, DefaultPaused, DefaultMaxJITsPerBlock, DefaultGoodTilPurgeAllowance, DefaultKeyWhitelistedLPs) | ||
} | ||
|
||
// ParamSetPairs get the params.ParamSet | ||
|
@@ -47,6 +51,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { | |
paramtypes.NewParamSetPair(KeyPaused, &p.Paused, validatePaused), | ||
paramtypes.NewParamSetPair(KeyMaxJITsPerBlock, &p.MaxJitsPerBlock, validateMaxJITsPerBlock), | ||
paramtypes.NewParamSetPair(KeyGoodTilPurgeAllowance, &p.GoodTilPurgeAllowance, validatePurgeAllowance), | ||
paramtypes.NewParamSetPair(KeyWhitelistedLPs, &p.WhitelistedLps, validateWhitelistedLPs), | ||
} | ||
} | ||
|
||
|
@@ -73,6 +78,11 @@ func (p Params) Validate() error { | |
if err := validatePurgeAllowance(p.GoodTilPurgeAllowance); err != nil { | ||
return err | ||
} | ||
|
||
if err := validateWhitelistedLPs(p.WhitelistedLps); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -118,3 +128,19 @@ func validatePurgeAllowance(v interface{}) error { | |
|
||
return nil | ||
} | ||
|
||
func validateWhitelistedLPs(v interface{}) error { | ||
whitelistedLPs, ok := v.([]string) | ||
if !ok { | ||
return fmt.Errorf("invalid parameter type: %T", v) | ||
} | ||
|
||
for _, addr := range whitelistedLPs { | ||
_, err := sdk.AccAddressFromBech32(addr) | ||
if err != nil { | ||
return fmt.Errorf("invalid Reserve address (%s): %w, ", addr, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why "reserve"? |
||
} | ||
} | ||
|
||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this check out of the loop? A small optimization.