From 616a686489bb85fd4c9bcf81c8b885ccdf7dda67 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 6 Jul 2022 01:56:46 +0200 Subject: [PATCH] feat(token registry): proto max collateral share (#1096) ## Description ref: #1095 --- ### Author Checklist _All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues._ I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] added appropriate labels to the PR - [x] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist _All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items._ I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- CHANGELOG.md | 1 + proto/umee/leverage/v1/leverage.proto | 9 + x/leverage/spec/02_state.md | 1 + x/leverage/types/leverage.pb.go | 143 ++++++++----- x/leverage/types/token.go | 4 + x/leverage/types/token_test.go | 276 ++++++++------------------ 6 files changed, 197 insertions(+), 237 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df5ed366bb..6a054efa4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - [913](https://github.com/umee-network/umee/pull/913) Changed update registry gov proposal to add and update tokens, but never delete them. - [918](https://github.com/umee-network/umee/pull/918) Add MarketSummary query to CLI. - [1068](https://github.com/umee-network/umee/pull/1068) Add a cache layer for token registry. +- [1096](https://github.com/umee-network/umee/pull/1096) Add `max_collateral_share` to the x/leverage token registry. - [1094](https://github.com/umee-network/umee/pull/1094) Added TotalCollateral query. - [1099](https://github.com/umee-network/umee/pull/1099) Added TotalBorrowed query. diff --git a/proto/umee/leverage/v1/leverage.proto b/proto/umee/leverage/v1/leverage.proto index 264d3cad03..b68c042b62 100644 --- a/proto/umee/leverage/v1/leverage.proto +++ b/proto/umee/leverage/v1/leverage.proto @@ -139,4 +139,13 @@ message Token { // and enable_msg_borrow set to false. Such tokens can be safely removed from the // oracle and price feeder as well. bool blacklist = 14; + + // Maximum collateral share specifies how much of the + // system's overall collateral be provided by a single token. + // Value is a percent; allowed values are in [0, 100] range. + // 100 means that the token has no restriction. 10 means maximum 10% of total + // collateral value can provided by this token. + uint32 max_collateral_share = 15 [ + (gogoproto.moretags) = "yaml:\"max_collateral_share\"" + ]; } diff --git a/x/leverage/spec/02_state.md b/x/leverage/spec/02_state.md index 6f2e2b96f0..2305483897 100644 --- a/x/leverage/spec/02_state.md +++ b/x/leverage/spec/02_state.md @@ -49,5 +49,6 @@ type Token struct { EnableMsgSupply bool EnableMsgBorrow bool Blacklist bool + MaxCollateralShare uint32 } ``` diff --git a/x/leverage/types/leverage.pb.go b/x/leverage/types/leverage.pb.go index f402b52130..a5b5fa2e9c 100644 --- a/x/leverage/types/leverage.pb.go +++ b/x/leverage/types/leverage.pb.go @@ -126,6 +126,12 @@ type Token struct { // and enable_msg_borrow set to false. Such tokens can be safely removed from the // oracle and price feeder as well. Blacklist bool `protobuf:"varint,14,opt,name=blacklist,proto3" json:"blacklist,omitempty"` + // Maximum collateral share specifies how much of the + // system's overall collateral be provided by a single token. + // Value is a percent; allowed values are in [0, 100] range. + // 100 means that the token has no restriction. 10 means maximum 10% of total + // collateral value can provided by this token. + MaxCollateralShare uint32 `protobuf:"varint,15,opt,name=max_collateral_share,json=maxCollateralShare,proto3" json:"max_collateral_share,omitempty" yaml:"max_collateral_share"` } func (m *Token) Reset() { *m = Token{} } @@ -203,6 +209,13 @@ func (m *Token) GetBlacklist() bool { return false } +func (m *Token) GetMaxCollateralShare() uint32 { + if m != nil { + return m.MaxCollateralShare + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "umee.leverage.v1.Params") proto.RegisterType((*Token)(nil), "umee.leverage.v1.Token") @@ -211,55 +224,57 @@ func init() { func init() { proto.RegisterFile("umee/leverage/v1/leverage.proto", fileDescriptor_8cb1bf9ea641ecc6) } var fileDescriptor_8cb1bf9ea641ecc6 = []byte{ - // 759 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xbf, 0x4f, 0x1b, 0x49, - 0x14, 0xf6, 0xde, 0x19, 0x0e, 0x0f, 0xd8, 0x86, 0xc5, 0xc0, 0xea, 0xce, 0xe7, 0x45, 0x23, 0xdd, - 0x89, 0x06, 0xef, 0x71, 0x49, 0xe5, 0xd2, 0x41, 0x09, 0xa0, 0x90, 0x44, 0x03, 0x11, 0x52, 0x9a, - 0xd5, 0x78, 0x3d, 0xb1, 0x57, 0x9e, 0xdd, 0x71, 0x76, 0xc6, 0xbf, 0x68, 0x52, 0x44, 0xe9, 0x53, - 0xa6, 0x89, 0x44, 0x9b, 0xff, 0x20, 0x7f, 0x02, 0x25, 0x65, 0x94, 0xc2, 0x8a, 0xa0, 0x49, 0xed, - 0xbf, 0x20, 0xda, 0x99, 0xb5, 0xbd, 0x06, 0x07, 0xc9, 0x82, 0xca, 0x3b, 0xdf, 0x7b, 0xfe, 0xbe, - 0x6f, 0xe6, 0xbd, 0x37, 0x03, 0xcc, 0x96, 0x47, 0x88, 0x45, 0x49, 0x9b, 0x04, 0xb8, 0x46, 0xac, - 0xf6, 0xce, 0xe8, 0xbb, 0xd8, 0x0c, 0x98, 0x60, 0xfa, 0x72, 0x98, 0x50, 0x1c, 0x81, 0xed, 0x9d, -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0x89, 0x31, 0x27, 0x3d, 0x3c, 0x9f, 0xd9, 0xc3, 0xdf, 0xca, - 0xc3, 0x74, 0x56, 0x88, 0x72, 0x32, 0x10, 0x2b, 0xc7, 0x91, 0x7b, 0x4a, 0x4a, 0xc9, 0x8f, 0x67, - 0x66, 0x02, 0x7e, 0x06, 0x60, 0xee, 0x98, 0x35, 0x88, 0xaf, 0x3f, 0x04, 0xa0, 0x82, 0x39, 0xb1, - 0xab, 0xc4, 0x67, 0x9e, 0xa1, 0x49, 0x2b, 0x6b, 0x83, 0xbe, 0xb9, 0xa2, 0xc8, 0xc7, 0x31, 0x88, - 0x52, 0xe1, 0x62, 0x37, 0xfc, 0xd6, 0x7d, 0x90, 0x09, 0x08, 0x27, 0x41, 0x7b, 0x54, 0x49, 0xd5, - 0x5e, 0x4f, 0x66, 0xde, 0xc4, 0x9a, 0xd2, 0x99, 0x64, 0x83, 0x28, 0x1d, 0x01, 0xd1, 0xe9, 0x75, - 0xc0, 0x8a, 0xc3, 0x28, 0xc5, 0x82, 0x04, 0x98, 0xda, 0x1d, 0xe2, 0xd6, 0xea, 0x22, 0x6a, 0x9e, - 0x83, 0x99, 0x25, 0x8d, 0x61, 0x47, 0x5f, 0x23, 0x84, 0x68, 0x79, 0x8c, 0x9d, 0x48, 0x48, 0x7f, - 0xa7, 0x81, 0xb5, 0xe9, 0xf3, 0xa4, 0x3a, 0xe7, 0xd9, 0xcc, 0xea, 0x79, 0xa5, 0xfe, 0x8b, 0x31, - 0xca, 0xd1, 0x69, 0xe3, 0xc3, 0xc1, 0xb2, 0x2c, 0x44, 0x85, 0x05, 0x01, 0xeb, 0xd8, 0x01, 0x16, - 0xc3, 0xae, 0xd9, 0x9f, 0x59, 0x7f, 0x23, 0x56, 0xd8, 0x18, 0x1f, 0x44, 0x99, 0x10, 0x2a, 0x4b, - 0x04, 0x61, 0x41, 0x42, 0xd1, 0x86, 0xeb, 0x37, 0x26, 0x44, 0xe7, 0xef, 0x26, 0x7a, 0x9d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x1a, 0xd4, 0xe5, 0xc2, 0xc8, 0x84, 0x0c, 0x68, 0x0c, 0x94, 0x92, - 0x3f, 0xce, 0x4c, 0xad, 0x7c, 0x70, 0x7e, 0x59, 0xd0, 0x2e, 0x2e, 0x0b, 0xda, 0xf7, 0xcb, 0x82, - 0xf6, 0xe1, 0xaa, 0x90, 0xb8, 0xb8, 0x2a, 0x24, 0xbe, 0x5e, 0x15, 0x12, 0xaf, 0xfe, 0x8b, 0x15, - 0x27, 0x7c, 0xb3, 0xb7, 0x7d, 0x22, 0x3a, 0x2c, 0x68, 0xc8, 0x85, 0xd5, 0xfe, 0xdf, 0xea, 0x8e, - 0x9f, 0x79, 0x59, 0xaa, 0xca, 0xbc, 0x7c, 0xb9, 0x1f, 0xfc, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x0d, - 0xd9, 0xde, 0x5f, 0x04, 0x08, 0x00, 0x00, + // 789 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x4d, 0x4f, 0x2b, 0x37, + 0x14, 0xcd, 0xb4, 0x81, 0x12, 0x43, 0x12, 0x18, 0x02, 0x8c, 0xda, 0x34, 0x83, 0x2c, 0xb5, 0x62, + 0x43, 0xa6, 0xb4, 0x5d, 0x65, 0x19, 0x50, 0x0b, 0xa8, 0xf4, 0xc3, 0x50, 0x21, 0x75, 0x33, 0x72, + 0x26, 0x6e, 0x32, 0x8a, 0x67, 0x9c, 0xda, 0xce, 0x17, 0x9b, 0x2e, 0xaa, 0xee, 0xbb, 0xec, 0xa6, + 0x12, 0x3f, 0xa3, 0x3f, 0x81, 0x25, 0xcb, 0xa7, 0xb7, 0x88, 0x9e, 0x60, 0xf3, 0xd6, 0x59, 0xbf, + 0xc5, 0xd3, 0xd8, 0x93, 0x64, 0x02, 0x79, 0x48, 0x11, 0xac, 0x62, 0x9f, 0x7b, 0x73, 0xce, 0xb1, + 0xef, 0xb5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29, 0x10, 0xe5, 0x35, 0x76, 0x26, 0x1a, 0xe7, 0x0a, + 0x79, 0xc0, 0xa4, 0x8b, 0x6b, 0x65, 0x9f, 0x60, 0xd2, 0x29, 0x49, 0x26, 0xdd, 0x00, 0x66, 0x11, + 0x64, 0x6a, 0x14, 0x7b, 0x2d, 0xea, 0x0b, 0x69, 0xe5, 0x22, 0x06, 0x34, 0x05, 0xcc, 0x5f, 0x40, + 0x21, 0xea, 0x9e, 0xc4, 0x45, 0x21, 0x9a, 0x98, 0x13, 0x2b, 0xaf, 0x96, 0x6b, 0x27, 0xbe, 0x43, + 0x73, 0xb2, 0xa2, 0xef, 0x10, 0xee, 0x1f, 0x4e, 0xd0, 0xf3, 0x08, 0xac, 0xa4, 0xdf, 0x5e, 0xdb, + 0x46, 0xf5, 0xf4, 0xe6, 0xae, 0x64, 0xdc, 0xde, 0x95, 0x8c, 0x37, 0x77, 0x25, 0xe3, 0x9f, 0xfb, + 0x52, 0xea, 0xf6, 0xbe, 0x94, 0x7a, 0x75, 0x5f, 0x4a, 0xfd, 0xf6, 0x55, 0xa2, 0xde, 0xd1, 0x33, + 0x60, 0x3f, 0x24, 0xb2, 0xc7, 0x78, 0x4b, 0x4d, 0x9c, 0xee, 0xd7, 0x4e, 0x7f, 0xfa, 0x72, 0x50, + 0xd5, 0xaf, 0x2d, 0xab, 0xc7, 0xc0, 0x37, 0xef, 0x03, 0x00, 0x00, 0xff, 0xff, 0x9c, 0x3f, 0x04, + 0x83, 0x57, 0x08, 0x00, 0x00, } func (this *Token) Equal(that interface{}) bool { @@ -323,6 +338,9 @@ func (this *Token) Equal(that interface{}) bool { if this.Blacklist != that1.Blacklist { return false } + if this.MaxCollateralShare != that1.MaxCollateralShare { + return false + } return true } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -408,6 +426,11 @@ func (m *Token) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MaxCollateralShare != 0 { + i = encodeVarintLeverage(dAtA, i, uint64(m.MaxCollateralShare)) + i-- + dAtA[i] = 0x78 + } if m.Blacklist { i-- if m.Blacklist { @@ -610,6 +633,9 @@ func (m *Token) Size() (n int) { if m.Blacklist { n += 2 } + if m.MaxCollateralShare != 0 { + n += 1 + sovLeverage(uint64(m.MaxCollateralShare)) + } return n } @@ -1249,6 +1275,25 @@ func (m *Token) Unmarshal(dAtA []byte) error { } } m.Blacklist = bool(v != 0) + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxCollateralShare", wireType) + } + m.MaxCollateralShare = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowLeverage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxCollateralShare |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipLeverage(dAtA[iNdEx:]) diff --git a/x/leverage/types/token.go b/x/leverage/types/token.go index 95df9ac2e5..5f7d52f56a 100644 --- a/x/leverage/types/token.go +++ b/x/leverage/types/token.go @@ -84,6 +84,10 @@ func (t Token) Validate() error { } } + if t.MaxCollateralShare > 100 { + return sdkerrors.ErrInvalidRequest.Wrap("Token.MaxCollateralShare must be in [0; 100] range") + } + return nil } diff --git a/x/leverage/types/token_test.go b/x/leverage/types/token_test.go index 20cab30c4d..1d6055c320 100644 --- a/x/leverage/types/token_test.go +++ b/x/leverage/types/token_test.go @@ -36,6 +36,7 @@ func TestUpdateRegistryProposal_String(t *testing.T) { EnableMsgSupply: true, EnableMsgBorrow: true, Blacklist: false, + MaxCollateralShare: 10, }, }, } @@ -56,241 +57,140 @@ registry: enable_msg_supply: true enable_msg_borrow: true blacklist: false + max_collateral_share: 10 ` require.Equal(t, expected, p.String()) } func TestToken_Validate(t *testing.T) { + validToken := func() types.Token { + return types.Token{ + BaseDenom: "uumee", + SymbolDenom: "umee", + Exponent: 6, + ReserveFactor: sdk.MustNewDecFromStr("0.25"), + CollateralWeight: sdk.MustNewDecFromStr("0.50"), + LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), + BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), + KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), + MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), + KinkUtilization: sdk.MustNewDecFromStr("0.75"), + LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), + EnableMsgSupply: true, + EnableMsgBorrow: true, + Blacklist: false, + MaxCollateralShare: 0, + } + } + invalidBaseToken := validToken() + invalidBaseToken.BaseDenom = "$$" + invalidBaseToken.SymbolDenom = "" + + invalidUToken := validToken() + invalidUToken.BaseDenom = "u/uumee" + invalidUToken.SymbolDenom = "" + + invalidReserveFactor := validToken() + invalidReserveFactor.ReserveFactor = sdk.MustNewDecFromStr("-0.25") + + invalidCollateralWeight := validToken() + invalidCollateralWeight.CollateralWeight = sdk.MustNewDecFromStr("50.00") + + invalidLiquidationThreshold := validToken() + invalidLiquidationThreshold.LiquidationThreshold = sdk.MustNewDecFromStr("0.40") + + invalidBaseBorrowRate := validToken() + invalidBaseBorrowRate.BaseBorrowRate = sdk.MustNewDecFromStr("-0.01") + + invalidKinkBorrowRate := validToken() + invalidKinkBorrowRate.KinkBorrowRate = sdk.MustNewDecFromStr("-0.05") + + invalidMaxBorrowRate := validToken() + invalidMaxBorrowRate.MaxBorrowRate = sdk.MustNewDecFromStr("-1.0") + + invalidKinkUtilization := validToken() + invalidKinkUtilization.KinkUtilization = sdk.ZeroDec() + + invalidLiquidationIncentive := validToken() + invalidLiquidationIncentive.LiquidationIncentive = sdk.MustNewDecFromStr("-0.05") + + invalidBlacklistedBorrow := validToken() + invalidBlacklistedBorrow.EnableMsgBorrow = false + invalidBlacklistedBorrow.Blacklist = true + + invalidBlacklistedSupply := validToken() + invalidBlacklistedSupply.EnableMsgSupply = false + invalidBlacklistedSupply.Blacklist = true + + invalidMaxCollateralShare := validToken() + invalidMaxCollateralShare.MaxCollateralShare = 101 + + validMaxCollateralShare := validToken() + validMaxCollateralShare.MaxCollateralShare = 100 + testCases := map[string]struct { input types.Token expectErr bool }{ "valid token": { - input: types.Token{ - BaseDenom: "uumee", - SymbolDenom: "umee", - Exponent: 6, - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: validToken(), }, "invalid base token": { - input: types.Token{ - BaseDenom: "$$", - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidBaseToken, expectErr: true, }, "invalid base token (utoken)": { - input: types.Token{ - BaseDenom: "u/uumee", - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidUToken, expectErr: true, }, "invalid reserve factor": { - input: types.Token{ - BaseDenom: "uumee", - ReserveFactor: sdk.MustNewDecFromStr("-0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidReserveFactor, expectErr: true, }, "invalid collateral weight": { - input: types.Token{ - BaseDenom: "uumee", - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("50.00"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidCollateralWeight, expectErr: true, }, "invalid liquidation threshold": { - input: types.Token{ - BaseDenom: "uumee", - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.40"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidLiquidationThreshold, expectErr: true, }, "invalid base borrow rate": { - input: types.Token{ - BaseDenom: "uumee", - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("-0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidBaseBorrowRate, expectErr: true, }, "invalid kink borrow rate": { - input: types.Token{ - BaseDenom: "uumee", - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("-0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidKinkBorrowRate, expectErr: true, }, "invalid max borrow rate": { - input: types.Token{ - BaseDenom: "uumee", - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("-1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidMaxBorrowRate, expectErr: true, }, "invalid kink utilization rate": { - input: types.Token{ - BaseDenom: "uumee", - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.ZeroDec(), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidKinkUtilization, expectErr: true, }, "invalid liquidation incentive": { - input: types.Token{ - BaseDenom: "uumee", - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("-0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: true, - Blacklist: false, - }, + input: invalidLiquidationIncentive, expectErr: true, }, "blacklisted but supply enabled": { - input: types.Token{ - BaseDenom: "uumee", - SymbolDenom: "umee", - Exponent: 6, - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: true, - EnableMsgBorrow: false, - Blacklist: true, - }, + input: invalidBlacklistedSupply, expectErr: true, }, "blacklisted but borrow enabled": { - input: types.Token{ - BaseDenom: "uumee", - SymbolDenom: "umee", - Exponent: 6, - ReserveFactor: sdk.MustNewDecFromStr("0.25"), - CollateralWeight: sdk.MustNewDecFromStr("0.50"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.50"), - BaseBorrowRate: sdk.MustNewDecFromStr("0.01"), - KinkBorrowRate: sdk.MustNewDecFromStr("0.05"), - MaxBorrowRate: sdk.MustNewDecFromStr("1.0"), - KinkUtilization: sdk.MustNewDecFromStr("0.75"), - LiquidationIncentive: sdk.MustNewDecFromStr("0.05"), - EnableMsgSupply: false, - EnableMsgBorrow: true, - Blacklist: true, - }, + input: invalidBlacklistedBorrow, expectErr: true, }, + "invalid max collateral share": { + input: invalidMaxCollateralShare, + expectErr: true, + }, + "valid max collateral share": { + input: validMaxCollateralShare, + expectErr: false, + }, } for name, tc := range testCases {