From 7c0699b291565c0cd7ca4b880e0d58878d42efcd Mon Sep 17 00:00:00 2001 From: Alpo <62043214+AlpinYukseloglu@users.noreply.github.com> Date: Mon, 5 Feb 2024 19:27:52 -0800 Subject: [PATCH] [Uptime Incentives]: Create gov param for internal incentive & group gauge uptime (#7418) * add internal uptime param to incentives module * fix init genesis test --- app/upgrades/v23/upgrades.go | 4 + proto/osmosis/incentives/params.proto | 13 +++ x/incentives/keeper/genesis_test.go | 1 + x/incentives/types/genesis.go | 1 + x/incentives/types/params.go | 35 +++++++- x/incentives/types/params.pb.go | 114 ++++++++++++++++++++------ 6 files changed, 143 insertions(+), 25 deletions(-) diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go index fcc5a9ee237..42b53f5d199 100644 --- a/app/upgrades/v23/upgrades.go +++ b/app/upgrades/v23/upgrades.go @@ -5,6 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + incentivestypes "github.com/osmosis-labs/osmosis/v22/x/incentives/types" + "github.com/osmosis-labs/osmosis/v22/app/keepers" "github.com/osmosis-labs/osmosis/v22/app/upgrades" ) @@ -23,6 +25,8 @@ func CreateUpgradeHandler( return nil, err } + keepers.IncentivesKeeper.SetParam(ctx, incentivestypes.KeyInternalUptime, incentivestypes.DefaultConcentratedUptime) + return migrations, nil } } diff --git a/proto/osmosis/incentives/params.proto b/proto/osmosis/incentives/params.proto index 8c1b35f21cd..255ee5cee93 100644 --- a/proto/osmosis/incentives/params.proto +++ b/proto/osmosis/incentives/params.proto @@ -3,6 +3,7 @@ package osmosis.incentives; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; +import "google/protobuf/duration.proto"; option go_package = "github.com/osmosis-labs/osmosis/v22/x/incentives/types"; @@ -31,4 +32,16 @@ message Params { // other users. repeated string unrestricted_creator_whitelist = 3 [ (gogoproto.moretags) = "yaml:\"unrestricted_creator_whitelist\"" ]; + + // internal_uptime is the uptime used for internal incentives on pools that + // use NoLock gauges (currently only Concentrated Liquidity pools). + // + // Since Group gauges route through internal gauges, this parameter affects + // the uptime of those incentives as well (i.e. distributions through volume + // splitting incentives will use this uptime). + google.protobuf.Duration internal_uptime = 4 [ + (gogoproto.nullable) = false, + (gogoproto.stdduration) = true, + (gogoproto.moretags) = "yaml:\"internal_uptime\"" + ]; } diff --git a/x/incentives/keeper/genesis_test.go b/x/incentives/keeper/genesis_test.go index ea642ab049b..51f8e491a47 100644 --- a/x/incentives/keeper/genesis_test.go +++ b/x/incentives/keeper/genesis_test.go @@ -187,6 +187,7 @@ func TestIncentivesInitGenesis(t *testing.T) { app.IncentivesKeeper.InitGenesis(ctx, types.GenesisState{ Params: types.Params{ DistrEpochIdentifier: "week", + InternalUptime: types.DefaultConcentratedUptime, }, Gauges: expectedGauges, LockableDurations: []time.Duration{ diff --git a/x/incentives/types/genesis.go b/x/incentives/types/genesis.go index 402033212f6..bec196507f0 100644 --- a/x/incentives/types/genesis.go +++ b/x/incentives/types/genesis.go @@ -18,6 +18,7 @@ func DefaultGenesis() *GenesisState { DistrEpochIdentifier: "week", GroupCreationFee: DefaultGroupCreationFee, UnrestrictedCreatorWhitelist: []string{}, + InternalUptime: DefaultConcentratedUptime, }, Gauges: []Gauge{}, LockableDurations: []time.Duration{ diff --git a/x/incentives/types/params.go b/x/incentives/types/params.go index 0759a758a7c..3d752c51294 100644 --- a/x/incentives/types/params.go +++ b/x/incentives/types/params.go @@ -2,10 +2,12 @@ package types import ( fmt "fmt" + time "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/osmosis/osmoutils" + cltypes "github.com/osmosis-labs/osmosis/v22/x/concentrated-liquidity/types" epochtypes "github.com/osmosis-labs/osmosis/x/epochs/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -16,6 +18,7 @@ var ( KeyDistrEpochIdentifier = []byte("DistrEpochIdentifier") KeyGroupCreationFee = []byte("GroupCreationFee") KeyCreatorWhitelist = []byte("CreatorWhitelist") + KeyInternalUptime = []byte("InternalUptime") // 100 OSMO DefaultGroupCreationFee = sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(100_000_000))) @@ -27,11 +30,12 @@ func ParamKeyTable() paramtypes.KeyTable { } // NewParams takes an epoch distribution identifier and group creation fee, then returns an incentives Params struct. -func NewParams(distrEpochIdentifier string, groupCreationFee sdk.Coins) Params { +func NewParams(distrEpochIdentifier string, groupCreationFee sdk.Coins, internalUptime time.Duration) Params { return Params{ DistrEpochIdentifier: distrEpochIdentifier, GroupCreationFee: groupCreationFee, UnrestrictedCreatorWhitelist: []string{}, + InternalUptime: internalUptime, } } @@ -41,6 +45,7 @@ func DefaultParams() Params { DistrEpochIdentifier: "week", GroupCreationFee: DefaultGroupCreationFee, UnrestrictedCreatorWhitelist: []string{}, + InternalUptime: DefaultConcentratedUptime, } } @@ -58,6 +63,10 @@ func (p Params) Validate() error { return err } + if err := ValidateInternalUptime(p.InternalUptime); err != nil { + return err + } + return nil } @@ -77,11 +86,35 @@ func ValidateGroupCreationFee(i interface{}) error { return v.Validate() } +func ValidateInternalUptime(i interface{}) error { + internalUptime, ok := i.(time.Duration) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + supported := false + for _, supportedUptime := range cltypes.SupportedUptimes { + if internalUptime == supportedUptime { + supported = true + + // We break here to save on iterations + break + } + } + + if !supported { + return cltypes.UptimeNotSupportedError{Uptime: internalUptime} + } + + return nil +} + // ParamSetPairs takes the parameter struct and associates the paramsubspace key and field of the parameters as a KVStore. func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(KeyDistrEpochIdentifier, &p.DistrEpochIdentifier, epochtypes.ValidateEpochIdentifierInterface), paramtypes.NewParamSetPair(KeyGroupCreationFee, &p.GroupCreationFee, ValidateGroupCreaionFee), paramtypes.NewParamSetPair(KeyCreatorWhitelist, &p.UnrestrictedCreatorWhitelist, osmoutils.ValidateAddressList), + paramtypes.NewParamSetPair(KeyInternalUptime, &p.InternalUptime, ValidateInternalUptime), } } diff --git a/x/incentives/types/params.pb.go b/x/incentives/types/params.pb.go index 640e72e72b2..b178d17664e 100644 --- a/x/incentives/types/params.pb.go +++ b/x/incentives/types/params.pb.go @@ -9,15 +9,19 @@ import ( types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" + _ "google.golang.org/protobuf/types/known/durationpb" io "io" math "math" math_bits "math/bits" + time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf +var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -43,6 +47,13 @@ type Params struct { // At the same time, it prevents spam by having a fee for all // other users. UnrestrictedCreatorWhitelist []string `protobuf:"bytes,3,rep,name=unrestricted_creator_whitelist,json=unrestrictedCreatorWhitelist,proto3" json:"unrestricted_creator_whitelist,omitempty" yaml:"unrestricted_creator_whitelist"` + // internal_uptime is the uptime used for internal incentives on pools that + // use NoLock gauges (currently only Concentrated Liquidity pools). + // + // Since Group gauges route through internal gauges, this parameter affects + // the uptime of those incentives as well (i.e. distributions through volume + // splitting incentives will use this uptime). + InternalUptime time.Duration `protobuf:"bytes,4,opt,name=internal_uptime,json=internalUptime,proto3,stdduration" json:"internal_uptime" yaml:"internal_uptime"` } func (m *Params) Reset() { *m = Params{} } @@ -99,6 +110,13 @@ func (m *Params) GetUnrestrictedCreatorWhitelist() []string { return nil } +func (m *Params) GetInternalUptime() time.Duration { + if m != nil { + return m.InternalUptime + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "osmosis.incentives.Params") } @@ -106,30 +124,35 @@ func init() { func init() { proto.RegisterFile("osmosis/incentives/params.proto", fileDescriptor_1cc8b460d089f845) } var fileDescriptor_1cc8b460d089f845 = []byte{ - // 365 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0xcf, 0x4a, 0xf3, 0x40, - 0x14, 0xc5, 0x93, 0x16, 0x0a, 0xcd, 0xb7, 0xf9, 0x08, 0x45, 0x6a, 0xd1, 0x49, 0x0d, 0x08, 0x71, - 0xd1, 0x8c, 0xad, 0xe0, 0xc2, 0x65, 0x8a, 0x82, 0xbb, 0xd2, 0x4d, 0xc1, 0x4d, 0xc8, 0x9f, 0xdb, - 0x74, 0xb0, 0xc9, 0x84, 0x99, 0x69, 0xb5, 0x6f, 0xe1, 0x73, 0xf8, 0x24, 0xdd, 0x08, 0x5d, 0xba, - 0xaa, 0xd2, 0xbe, 0x41, 0x9f, 0x40, 0x32, 0x93, 0x6a, 0x17, 0xe2, 0x6a, 0x66, 0xee, 0xf9, 0xcd, - 0xbd, 0xe7, 0x70, 0x0d, 0x8b, 0xf2, 0x94, 0x72, 0xc2, 0x31, 0xc9, 0x22, 0xc8, 0x04, 0x99, 0x03, - 0xc7, 0x79, 0xc0, 0x82, 0x94, 0xbb, 0x39, 0xa3, 0x82, 0x9a, 0x66, 0x09, 0xb8, 0x3f, 0x40, 0xab, - 0x91, 0xd0, 0x84, 0x4a, 0x19, 0x17, 0x37, 0x45, 0xb6, 0x50, 0x24, 0x51, 0x1c, 0x06, 0x1c, 0xf0, - 0xbc, 0x1b, 0x82, 0x08, 0xba, 0x38, 0xa2, 0x24, 0x53, 0xba, 0xfd, 0x56, 0x31, 0x6a, 0x03, 0xd9, - 0xda, 0x1c, 0x19, 0x47, 0x31, 0xe1, 0x82, 0xf9, 0x90, 0xd3, 0x68, 0xe2, 0x93, 0xb8, 0xe8, 0x3c, - 0x26, 0xc0, 0x9a, 0x7a, 0x5b, 0x77, 0xea, 0xde, 0xd9, 0x6e, 0x6d, 0x9d, 0x2e, 0x82, 0x74, 0x7a, - 0x63, 0xff, 0xce,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, 0x02, 0x00, 0x00, + // 433 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0x6e, 0xac, 0x2c, 0x6c, 0x04, 0x95, 0xb0, 0x2c, 0x75, 0xd1, 0x49, 0x0d, 0x08, 0xf5, 0xb0, + 0x33, 0x6e, 0x05, 0x0f, 0x1e, 0x53, 0x15, 0xbc, 0x2d, 0x05, 0x59, 0xf0, 0x12, 0x26, 0xc9, 0x6b, + 0x3a, 0x98, 0xe4, 0x85, 0x99, 0x49, 0xb5, 0xff, 0xc2, 0xa3, 0xbf, 0xc1, 0xbb, 0xff, 0x61, 0x8f, + 0x7b, 0xf4, 0x94, 0x4a, 0xfb, 0x0f, 0xfa, 0x0b, 0x24, 0x33, 0x89, 0x16, 0x91, 0x3d, 0x25, 0xf3, + 0x7d, 0xdf, 0xe3, 0x7b, 0xdf, 0x7b, 0xcf, 0xf5, 0x51, 0x15, 0xa8, 0x84, 0x62, 0xa2, 0x4c, 0xa0, + 0xd4, 0x62, 0x05, 0x8a, 0x55, 0x5c, 0xf2, 0x42, 0xd1, 0x4a, 0xa2, 0x46, 0xcf, 0xeb, 0x04, 0xf4, + 0xaf, 0xe0, 0xec, 0x24, 0xc3, 0x0c, 0x0d, 0xcd, 0xda, 0x3f, 0xab, 0x3c, 0x23, 0x89, 0x91, 0xb2, + 0x98, 0x2b, 0x60, 0xab, 0x8b, 0x18, 0x34, 0xbf, 0x60, 0x09, 0x8a, 0xb2, 0xe7, 0x33, 0xc4, 0x2c, + 0x07, 0x66, 0x5e, 0x71, 0xbd, 0x60, 0x69, 0x2d, 0xb9, 0x16, 0xd8, 0xf1, 0xc1, 0x8f, 0xa1, 0x7b, + 0x74, 0x69, 0xac, 0xbd, 0x2b, 0xf7, 0x34, 0x15, 0x4a, 0xcb, 0x08, 0x2a, 0x4c, 0x96, 0x91, 0x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0d, 0xfc, 0x53, 0x1f, 0x7c, 0xdb, 0xf8, 0xce, 0xfc, 0x7e, 0x8f, + 0x7e, 0x30, 0x60, 0x78, 0x79, 0xbd, 0x25, 0xce, 0xcd, 0x96, 0x38, 0xbf, 0xb6, 0xc4, 0xf9, 0xba, + 0x23, 0x83, 0x9b, 0x1d, 0x19, 0xfc, 0xdc, 0x91, 0xc1, 0xc7, 0x57, 0x07, 0xe3, 0xea, 0xce, 0xe8, + 0x3c, 0xe7, 0xb1, 0xea, 0x1f, 0x6c, 0x35, 0x9d, 0xb2, 0x2f, 0x87, 0xa7, 0x67, 0x46, 0x18, 0x1f, + 0x99, 0xc6, 0x5e, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x96, 0xc5, 0xb3, 0x4e, 0x9d, 0x02, 0x00, + 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -152,6 +175,14 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + n1, err1 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.InternalUptime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.InternalUptime):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintParams(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 if len(m.UnrestrictedCreatorWhitelist) > 0 { for iNdEx := len(m.UnrestrictedCreatorWhitelist) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.UnrestrictedCreatorWhitelist[iNdEx]) @@ -218,6 +249,8 @@ func (m *Params) Size() (n int) { n += 1 + l + sovParams(uint64(l)) } } + l = github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.InternalUptime) + n += 1 + l + sovParams(uint64(l)) return n } @@ -354,6 +387,39 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.UnrestrictedCreatorWhitelist = append(m.UnrestrictedCreatorWhitelist, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InternalUptime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdDurationUnmarshal(&m.InternalUptime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:])