Skip to content
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

fix: gov special assets fix for 6.0 #2247

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions x/leverage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,10 @@ func (s msgServer) GovUpdateSpecialAssets(
for _, b := range set.Assets {
if a != b {
pair := types.SpecialAssetPair{
Collateral: a,
Borrow: b,
CollateralWeight: set.CollateralWeight,
Collateral: a,
Borrow: b,
CollateralWeight: set.CollateralWeight,
LiquidationThreshold: set.LiquidationThreshold,
toteki marked this conversation as resolved.
Show resolved Hide resolved
}
// sets or overrides (or deletes on zero collateral weight) each pair
if err := s.keeper.SetSpecialAssetPair(ctx, pair); err != nil {
Expand Down
129 changes: 129 additions & 0 deletions x/leverage/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,135 @@ func (s *IntegrationTestSuite) TestUpdateRegistry() {
}
}

func (s *IntegrationTestSuite) TestUpdateSpecialAssets() {
govAccAddr := checkers.GovModuleAddr

testCases := []struct {
name string
req *types.MsgGovUpdateSpecialAssets
expectErr bool
errMsg string
}{
{
"empty",
&types.MsgGovUpdateSpecialAssets{
Authority: govAccAddr,
Description: "test",
Sets: []types.SpecialAssetSet{},
Pairs: []types.SpecialAssetPair{},
},
true,
"empty",
},
{
"invalid set",
&types.MsgGovUpdateSpecialAssets{
Authority: govAccAddr,
Description: "test",
Sets: []types.SpecialAssetSet{
{
Assets: []string{"test1", "test2"},
CollateralWeight: sdk.MustNewDecFromStr("0.8"),
},
},
Pairs: []types.SpecialAssetPair{},
},
true,
"nil",
},
{
"valid set",
&types.MsgGovUpdateSpecialAssets{
Authority: govAccAddr,
Description: "test",
Sets: []types.SpecialAssetSet{
{
Assets: []string{"test1", "test2"},
CollateralWeight: sdk.MustNewDecFromStr("0.8"),
LiquidationThreshold: sdk.MustNewDecFromStr("0.9"),
},
},
Pairs: []types.SpecialAssetPair{},
},
false,
"",
},
{
"invalid pair",
&types.MsgGovUpdateSpecialAssets{
Authority: govAccAddr,
Description: "test",
Sets: []types.SpecialAssetSet{},
Pairs: []types.SpecialAssetPair{
{
Borrow: "test1",
Collateral: "test2",
CollateralWeight: sdk.MustNewDecFromStr("0.8"),
},
},
},
true,
"nil",
},
{
"valid pair",
&types.MsgGovUpdateSpecialAssets{
Authority: govAccAddr,
Description: "test",
Sets: []types.SpecialAssetSet{},
Pairs: []types.SpecialAssetPair{
{
Borrow: "test1",
Collateral: "test2",
CollateralWeight: sdk.MustNewDecFromStr("0.8"),
LiquidationThreshold: sdk.MustNewDecFromStr("0.9"),
},
},
},
false,
"",
},
{
"valid set and pair",
&types.MsgGovUpdateSpecialAssets{
Authority: govAccAddr,
Description: "test",
Sets: []types.SpecialAssetSet{
{
Assets: []string{"test1", "test2"},
CollateralWeight: sdk.MustNewDecFromStr("0.8"),
LiquidationThreshold: sdk.MustNewDecFromStr("0.9"),
},
},
Pairs: []types.SpecialAssetPair{
{
Borrow: "test1",
Collateral: "test2",
CollateralWeight: sdk.MustNewDecFromStr("0.8"),
LiquidationThreshold: sdk.MustNewDecFromStr("0.9"),
},
},
},
false,
"",
},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
err := tc.req.ValidateBasic()
if err == nil {
_, err = s.msgSrvr.GovUpdateSpecialAssets(s.ctx, tc.req)
}
if tc.expectErr {
s.Require().ErrorContains(err, tc.errMsg)
} else {
s.Require().NoError(err)
}
})
}
}

func (s *IntegrationTestSuite) TestMsgSupply() {
type testCase struct {
msg string
Expand Down
15 changes: 13 additions & 2 deletions x/leverage/types/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"github.com/umee-network/umee/v6/util/coin"
)

var halfDec = sdk.MustNewDecFromStr("0.5")
var one = sdk.OneDec()
var (
halfDec = sdk.MustNewDecFromStr("0.5")
one = sdk.OneDec()
)

// ValidateBaseDenom validates a denom and ensures it is not a uToken.
func ValidateBaseDenom(denom string) error {
Expand Down Expand Up @@ -175,6 +177,11 @@ func (p SpecialAssetPair) Validate() error {
return err
}

if p.CollateralWeight.IsNil() || p.LiquidationThreshold.IsNil() {
return fmt.Errorf("nil collateral weight or liquidation threshold for asset pair (%s,%s)",
p.Borrow, p.Collateral)
}

// Collateral Weight is non-negative and less than 1.
if p.CollateralWeight.IsNegative() || p.CollateralWeight.GTE(sdk.OneDec()) {
return fmt.Errorf("invalid collateral rate: %s", p.CollateralWeight)
Expand Down Expand Up @@ -202,6 +209,10 @@ func (s SpecialAssetSet) Validate() error {
denoms[a] = true
}

if s.CollateralWeight.IsNil() || s.LiquidationThreshold.IsNil() {
return fmt.Errorf("nil collateral weight or liquidation threshold for asset set %s)", s.Assets)
}

// Collateral Weight is non-negative and less than 1.
if s.CollateralWeight.IsNegative() || s.CollateralWeight.GTE(sdk.OneDec()) {
return fmt.Errorf("invalid collateral rate: %s", s.CollateralWeight)
Expand Down