Skip to content

Commit

Permalink
[Uptime Incentives]: Create gov param for internal incentive & group …
Browse files Browse the repository at this point in the history
…gauge uptime (#7418)

* add internal uptime param to incentives module

* fix init genesis test
  • Loading branch information
AlpinYukseloglu authored Feb 6, 2024
1 parent fda7971 commit 7c0699b
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 25 deletions.
4 changes: 4 additions & 0 deletions app/upgrades/v23/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -23,6 +25,8 @@ func CreateUpgradeHandler(
return nil, err
}

keepers.IncentivesKeeper.SetParam(ctx, incentivestypes.KeyInternalUptime, incentivestypes.DefaultConcentratedUptime)

return migrations, nil
}
}
13 changes: 13 additions & 0 deletions proto/osmosis/incentives/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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\""
];
}
1 change: 1 addition & 0 deletions x/incentives/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions x/incentives/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func DefaultGenesis() *GenesisState {
DistrEpochIdentifier: "week",
GroupCreationFee: DefaultGroupCreationFee,
UnrestrictedCreatorWhitelist: []string{},
InternalUptime: DefaultConcentratedUptime,
},
Gauges: []Gauge{},
LockableDurations: []time.Duration{
Expand Down
35 changes: 34 additions & 1 deletion x/incentives/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)))
Expand All @@ -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,
}
}

Expand All @@ -41,6 +45,7 @@ func DefaultParams() Params {
DistrEpochIdentifier: "week",
GroupCreationFee: DefaultGroupCreationFee,
UnrestrictedCreatorWhitelist: []string{},
InternalUptime: DefaultConcentratedUptime,
}
}

Expand All @@ -58,6 +63,10 @@ func (p Params) Validate() error {
return err
}

if err := ValidateInternalUptime(p.InternalUptime); err != nil {
return err
}

return nil
}

Expand All @@ -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),
}
}
114 changes: 90 additions & 24 deletions x/incentives/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c0699b

Please sign in to comment.