From 8417bf841fdb634c9f2057937baf01a5077b6973 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 29 Mar 2022 14:32:13 -0700 Subject: [PATCH 1/5] param++ --- proto/umee/leverage/v1beta1/leverage.proto | 7 ++ x/leverage/keeper/keeper.go | 6 + x/leverage/simulation/genesis.go | 13 ++ x/leverage/simulation/params.go | 5 + x/leverage/spec/07_params.md | 12 +- x/leverage/types/leverage.pb.go | 137 ++++++++++++++------- x/leverage/types/params.go | 24 ++++ 7 files changed, 158 insertions(+), 46 deletions(-) diff --git a/proto/umee/leverage/v1beta1/leverage.proto b/proto/umee/leverage/v1beta1/leverage.proto index 64782c2754..07be34f3ed 100644 --- a/proto/umee/leverage/v1beta1/leverage.proto +++ b/proto/umee/leverage/v1beta1/leverage.proto @@ -29,6 +29,13 @@ message Params { (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"oracle_reward_factor\"" ]; + // The small_liquidation_size determines the USD value at which a borrow is considered small + // enough to be liquidated in a single transaction, bypassing dynamic close factor. + string small_liquidation_size = 5 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"small_liquidation_size\"" + ]; } // Token defines a token, along with its capital metadata, in the Umee capital diff --git a/x/leverage/keeper/keeper.go b/x/leverage/keeper/keeper.go index 47b78b65f3..e999e2e591 100644 --- a/x/leverage/keeper/keeper.go +++ b/x/leverage/keeper/keeper.go @@ -584,6 +584,12 @@ func (k Keeper) LiquidationParams( return liquidationIncentive, sdk.OneDec(), nil } + // special case: If borrowed value is less than small liquidation size, + // close factor is always 1 + if borrowed.LTE(k.GetParams(ctx).SmallLiquidationSize) { + return liquidationIncentive, sdk.OneDec(), nil + } + params := k.GetParams(ctx) // special case: If complete liquidation threshold is zero, close factor is always 1 if params.CompleteLiquidationThreshold.IsZero() { diff --git a/x/leverage/simulation/genesis.go b/x/leverage/simulation/genesis.go index b08809d48f..a6a2d9e103 100644 --- a/x/leverage/simulation/genesis.go +++ b/x/leverage/simulation/genesis.go @@ -15,6 +15,7 @@ const ( completeLiquidationThresholdKey = "complete_liquidation_threshold" minimumCloseFactorKey = "minimum_close_factor" oracleRewardFactorKey = "oracle_reward_factor" + smallLiquidationSizeKey = "small_liquidation_size" ) // GenCompleteLiquidationThreshold produces a randomized CompleteLiquidationThreshold in the range of [0.050, 0.100] @@ -32,6 +33,11 @@ func GenOracleRewardFactor(r *rand.Rand) sdk.Dec { return sdk.NewDecWithPrec(005, 3).Add(sdk.NewDecWithPrec(int64(r.Intn(995)), 3)) } +// GenSmallLiquidationSize produces a randomized SmallLiquidationSize in the range of [0, 1000] +func GenSmallLiquidationSize(r *rand.Rand) sdk.Dec { + return sdk.NewDec(int64(r.Intn(1000))) +} + // RandomizedGenState generates a random GenesisState for oracle func RandomizedGenState(simState *module.SimulationState) { var completeLiquidationThreshold sdk.Dec @@ -52,11 +58,18 @@ func RandomizedGenState(simState *module.SimulationState) { func(r *rand.Rand) { oracleRewardFactor = GenOracleRewardFactor(r) }, ) + var smallLiquidationSize sdk.Dec + simState.AppParams.GetOrGenerate( + simState.Cdc, smallLiquidationSizeKey, &smallLiquidationSize, simState.Rand, + func(r *rand.Rand) { smallLiquidationSize = GenSmallLiquidationSize(r) }, + ) + leverageGenesis := types.NewGenesisState( types.Params{ CompleteLiquidationThreshold: completeLiquidationThreshold, MinimumCloseFactor: minimumCloseFactor, OracleRewardFactor: oracleRewardFactor, + SmallLiquidationSize: smallLiquidationSize, }, []types.Token{}, []types.AdjustedBorrow{}, diff --git a/x/leverage/simulation/params.go b/x/leverage/simulation/params.go index 71c6435b07..a78dec00e1 100644 --- a/x/leverage/simulation/params.go +++ b/x/leverage/simulation/params.go @@ -29,5 +29,10 @@ func ParamChanges(r *rand.Rand) []simtypes.ParamChange { return fmt.Sprintf("\"%s\"", GenOracleRewardFactor(r)) }, ), + simulation.NewSimParamChange(types.ModuleName, string(types.KeySmallLiquidationSize), + func(r *rand.Rand) string { + return fmt.Sprintf("\"%s\"", GenSmallLiquidationSize(r)) + }, + ), } } diff --git a/x/leverage/spec/07_params.md b/x/leverage/spec/07_params.md index c3606cab2e..ff04415bcb 100644 --- a/x/leverage/spec/07_params.md +++ b/x/leverage/spec/07_params.md @@ -7,19 +7,25 @@ The leverage module contains the following parameters: | CompleteLiquidationThreshold | sdk.Dec | 0.1 | | MinimumCloseFactor | sdk.Dec | 0.01 | | OracleRewardFactor | sdk.Dec | 0.01 | +| SmallLiquidationSize | sdk.Dec | 100.00 | ## CompleteLiquidationThreshold -CompleteLiquidationThreshold governs how far above their borrow limit a borrower +CompleteLiquidationThreshold governs how far above their liquidation limit a borrower must be to have a [Close Factor](01_concepts.md#Close-Factor) of 1.0 - that is, to be eligible for full liquidation in a single liquidation event. ## MinimumCloseFactor MinimumCloseFactor is the [Close Factor](01_concepts.md#Close-Factor) for -borrows that are just above their borrow limit. +borrows that are just above their liquidation limit. ## OracleRewardFactor OracleRewardFactor is the portion of borrow interest accrued that goes to fund -the `x/oracle` reward pool. \ No newline at end of file +the `x/oracle` reward pool. + +## SmallLiquidationSize + +SmallLiquidationSize is the borrow value in USD below which [Close Factor](01_concepts.md#Close-Factor) +is always 1.0 once the borrow is eligible for liquidation. \ No newline at end of file diff --git a/x/leverage/types/leverage.pb.go b/x/leverage/types/leverage.pb.go index 7e52dd6654..63d1e2773b 100644 --- a/x/leverage/types/leverage.pb.go +++ b/x/leverage/types/leverage.pb.go @@ -35,6 +35,9 @@ type Params struct { // The oracle_reward_factor determines the portion of interest accrued on borrows that is // sent to the oracle module to fund its reward pool. OracleRewardFactor github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=oracle_reward_factor,json=oracleRewardFactor,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"oracle_reward_factor" yaml:"oracle_reward_factor"` + // The small_liquidation_size determines the USD value at which a borrow is considered small + // enough to be liquidated in a single transaction, bypassing dynamic close factor. + SmallLiquidationSize github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=small_liquidation_size,json=smallLiquidationSize,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"small_liquidation_size" yaml:"small_liquidation_size"` } func (m *Params) Reset() { *m = Params{} } @@ -171,49 +174,51 @@ func init() { } var fileDescriptor_f9aab5daf3352690 = []byte{ - // 666 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x4b, 0x6f, 0x13, 0x3d, - 0x14, 0xcd, 0x7c, 0x7d, 0x7c, 0x8d, 0x4b, 0x5f, 0xd3, 0x86, 0x46, 0x50, 0xcd, 0x14, 0x0b, 0x50, - 0x37, 0xcd, 0xa8, 0x82, 0x55, 0x96, 0xa1, 0xa2, 0x14, 0x01, 0x42, 0x56, 0x51, 0x25, 0x36, 0x23, - 0x67, 0x72, 0x49, 0x46, 0xb1, 0xc7, 0xc1, 0xe3, 0x3c, 0xca, 0x06, 0x09, 0x24, 0xd6, 0x2c, 0xd9, - 0x20, 0xf5, 0x27, 0xf0, 0x33, 0xba, 0xec, 0x12, 0xb1, 0x88, 0x50, 0xbb, 0x61, 0x9d, 0x5f, 0x80, - 0xc6, 0x9e, 0xbc, 0xaa, 0x80, 0x14, 0x95, 0x55, 0xec, 0x73, 0xaf, 0xcf, 0x39, 0x9e, 0x7b, 0xe3, - 0x8b, 0xee, 0x36, 0x39, 0x80, 0xc7, 0xa0, 0x05, 0x92, 0x56, 0xc1, 0x6b, 0xed, 0x95, 0x41, 0xd1, - 0xbd, 0x01, 0x50, 0x68, 0x48, 0xa1, 0x84, 0x7d, 0x27, 0xc9, 0x8a, 0x40, 0xb5, 0x85, 0xac, 0x17, - 0x92, 0x75, 0x61, 0x90, 0x90, 0x9e, 0xb8, 0xb5, 0x51, 0x15, 0x55, 0xa1, 0xb3, 0xbd, 0x64, 0x65, - 0x0e, 0xe2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b, 0x53, 0x11, 0x2d, - 0xbc, 0x70, 0xbd, 0x0a, 0x4f, 0x24, 0xc5, 0x64, 0x3d, 0xc1, 0x5f, 0x0d, 0x61, 0x6d, 0xe2, 0x6a, - 0x9b, 0x85, 0x51, 0x00, 0x91, 0x0a, 0x5b, 0x90, 0xcf, 0xfe, 0xbb, 0x36, 0x1b, 0x90, 0x8e, 0xb7, - 0xd9, 0x61, 0x1f, 0xb6, 0x8b, 0xe8, 0x46, 0x7c, 0xc2, 0xcb, 0x82, 0xa5, 0xaf, 0x01, 0xd2, 0xda, - 0x9b, 0xbd, 0xae, 0xbb, 0x6e, 0xd8, 0x46, 0xa3, 0x98, 0x2c, 0x9a, 0xad, 0x79, 0x11, 0x3c, 0xb4, - 0x00, 0x9d, 0x86, 0x88, 0x20, 0x52, 0xf9, 0xc5, 0x6d, 0x6b, 0x67, 0xa9, 0xb4, 0xde, 0xeb, 0xba, - 0x2b, 0xe6, 0x5c, 0x3f, 0x82, 0xc9, 0x20, 0xa9, 0x38, 0xfb, 0xeb, 0xd4, 0xb5, 0x4a, 0x07, 0x67, - 0x17, 0x8e, 0x75, 0x7e, 0xe1, 0x58, 0x3f, 0x2f, 0x1c, 0xeb, 0xf3, 0xa5, 0x93, 0x39, 0xbf, 0x74, - 0x32, 0xdf, 0x2f, 0x9d, 0xcc, 0xeb, 0xdd, 0x91, 0xab, 0x26, 0xd3, 0x68, 0x37, 0x1d, 0x4d, 0x7a, - 0xe3, 0x75, 0x86, 0xe3, 0x4c, 0xdf, 0xba, 0x3c, 0xaf, 0x67, 0xd1, 0x83, 0xdf, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x4e, 0x9a, 0x61, 0x29, 0xec, 0x06, 0x00, 0x00, + // 701 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x4b, 0x6f, 0x13, 0x3b, + 0x14, 0xce, 0xdc, 0x9b, 0x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f, 0x6b, 0xb3, 0x01, 0xe9, 0x78, + 0x9b, 0xed, 0xf7, 0x61, 0xbb, 0x88, 0xfe, 0x0f, 0x8e, 0x44, 0x59, 0xf2, 0xf8, 0x36, 0x40, 0x46, + 0x7b, 0xbd, 0xd7, 0x75, 0x56, 0xe3, 0xab, 0x66, 0x24, 0x8a, 0xc9, 0x7c, 0x34, 0x8d, 0x6e, 0x84, + 0x02, 0x9a, 0x83, 0x4e, 0x43, 0xfa, 0xe0, 0xeb, 0xec, 0xfc, 0xa6, 0xb5, 0xb5, 0x50, 0x5a, 0xed, + 0x75, 0x9d, 0xa5, 0x68, 0x5d, 0x3f, 0x82, 0xc9, 0x20, 0xa9, 0x98, 0xfc, 0x79, 0xe2, 0x58, 0xa5, + 0xbd, 0xd3, 0xf3, 0x9c, 0x75, 0x76, 0x9e, 0xb3, 0x7e, 0x9c, 0xe7, 0xac, 0x4f, 0x17, 0xb9, 0xc4, + 0xd9, 0x45, 0x2e, 0xf1, 0xed, 0x22, 0x97, 0x78, 0xb5, 0x3d, 0xb2, 0xd5, 0xf0, 0x55, 0xdc, 0x8e, + 0x9f, 0x48, 0x33, 0x29, 0x74, 0x86, 0xcf, 0xaa, 0xd9, 0x75, 0x79, 0xd6, 0xbc, 0x89, 0x77, 0x7f, + 0x05, 0x00, 0x00, 0xff, 0xff, 0xb8, 0x78, 0x89, 0x19, 0x74, 0x07, 0x00, 0x00, } func (this *Token) Equal(that interface{}) bool { @@ -290,6 +295,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.SmallLiquidationSize.Size() + i -= size + if _, err := m.SmallLiquidationSize.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintLeverage(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a { size := m.OracleRewardFactor.Size() i -= size @@ -468,6 +483,8 @@ func (m *Params) Size() (n int) { n += 1 + l + sovLeverage(uint64(l)) l = m.OracleRewardFactor.Size() n += 1 + l + sovLeverage(uint64(l)) + l = m.SmallLiquidationSize.Size() + n += 1 + l + sovLeverage(uint64(l)) return n } @@ -644,6 +661,40 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SmallLiquidationSize", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowLeverage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthLeverage + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthLeverage + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SmallLiquidationSize.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipLeverage(dAtA[iNdEx:]) diff --git a/x/leverage/types/params.go b/x/leverage/types/params.go index 81adb55cd2..2641e3ac19 100644 --- a/x/leverage/types/params.go +++ b/x/leverage/types/params.go @@ -14,12 +14,14 @@ var ( KeyCompleteLiquidationThreshold = []byte("CompleteLiquidationThreshold") KeyMinimumCloseFactor = []byte("MinimumCloseFactor") KeyOracleRewardFactor = []byte("OracleRewardFactor") + KeySmallLiquidationSize = []byte("SmallLiquidationSize") ) var ( defaultCompleteLiquidationThreshold = sdk.MustNewDecFromStr("0.1") defaultMinimumCloseFactor = sdk.MustNewDecFromStr("0.01") defaultOracleRewardFactor = sdk.MustNewDecFromStr("0.01") + defaultSmallLiquidationSize = sdk.MustNewDecFromStr("100.00") ) func NewParams() Params { @@ -45,6 +47,11 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { &p.OracleRewardFactor, validateOracleRewardFactor, ), + paramtypes.NewParamSetPair( + KeySmallLiquidationSize, + &p.SmallLiquidationSize, + validateSmallLiquidationSize, + ), } } @@ -66,6 +73,7 @@ func DefaultParams() Params { CompleteLiquidationThreshold: defaultCompleteLiquidationThreshold, MinimumCloseFactor: defaultMinimumCloseFactor, OracleRewardFactor: defaultOracleRewardFactor, + SmallLiquidationSize: defaultSmallLiquidationSize, } } @@ -80,6 +88,9 @@ func (p Params) Validate() error { if err := validateOracleRewardFactor(p.OracleRewardFactor); err != nil { return err } + if err := validateSmallLiquidationSize(p.SmallLiquidationSize); err != nil { + return err + } return nil } @@ -127,3 +138,16 @@ func validateOracleRewardFactor(i interface{}) error { return nil } + +func validateSmallLiquidationSize(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v.IsNegative() { + return fmt.Errorf("small liquidation size cannot be negative: %d", v) + } + + return nil +} From fba7707875d38f7f34240027c5cd1b1c92154a8c Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 29 Mar 2022 14:40:43 -0700 Subject: [PATCH 2/5] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df61c15aba..dff719451f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +- [723](https://github.com/umee-network/umee/pull/723) Add leverage parameter SmallLiquidationSize - [711](https://github.com/umee-network/umee/pull/711) Clarify error message for negative elapsed time case. ## [v2.0.0](https://github.com/umee-network/umee/releases/tag/v2.0.0) - 2022-03-25 From f3455fa58caf10595c061c161c4dc4ac374a3aea Mon Sep 17 00:00:00 2001 From: Adam Moser <63419657+toteki@users.noreply.github.com> Date: Tue, 29 Mar 2022 14:42:55 -0700 Subject: [PATCH 3/5] ++ --- x/leverage/spec/07_params.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/leverage/spec/07_params.md b/x/leverage/spec/07_params.md index ff04415bcb..626809e990 100644 --- a/x/leverage/spec/07_params.md +++ b/x/leverage/spec/07_params.md @@ -28,4 +28,4 @@ the `x/oracle` reward pool. ## SmallLiquidationSize SmallLiquidationSize is the borrow value in USD below which [Close Factor](01_concepts.md#Close-Factor) -is always 1.0 once the borrow is eligible for liquidation. \ No newline at end of file +is always 1. \ No newline at end of file From 0fb60e947c6a8c4215b17f7b1c1c7fe49e7f080b Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Wed, 30 Mar 2022 08:31:07 -0700 Subject: [PATCH 4/5] params only once --- x/leverage/keeper/keeper.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/leverage/keeper/keeper.go b/x/leverage/keeper/keeper.go index e999e2e591..31679a7704 100644 --- a/x/leverage/keeper/keeper.go +++ b/x/leverage/keeper/keeper.go @@ -584,13 +584,14 @@ func (k Keeper) LiquidationParams( return liquidationIncentive, sdk.OneDec(), nil } + params := k.GetParams(ctx) + // special case: If borrowed value is less than small liquidation size, // close factor is always 1 - if borrowed.LTE(k.GetParams(ctx).SmallLiquidationSize) { + if borrowed.LTE(params.SmallLiquidationSize) { return liquidationIncentive, sdk.OneDec(), nil } - params := k.GetParams(ctx) // special case: If complete liquidation threshold is zero, close factor is always 1 if params.CompleteLiquidationThreshold.IsZero() { return liquidationIncentive, sdk.OneDec(), nil From cd1bd3783408bfc5b910a4a24227adba31d43231 Mon Sep 17 00:00:00 2001 From: Adam Moser <63419657+toteki@users.noreply.github.com> Date: Wed, 30 Mar 2022 08:31:58 -0700 Subject: [PATCH 5/5] Update CHANGELOG.md Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dff719451f..fe41e0dc4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,7 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements -- [723](https://github.com/umee-network/umee/pull/723) Add leverage parameter SmallLiquidationSize +- [723](https://github.com/umee-network/umee/pull/723) Add leverage parameter SmallLiquidationSize, which determines the USD value at which a borrow is considered small enough to be liquidated in a single transaction. - [711](https://github.com/umee-network/umee/pull/711) Clarify error message for negative elapsed time case. ## [v2.0.0](https://github.com/umee-network/umee/releases/tag/v2.0.0) - 2022-03-25