Skip to content

Commit

Permalink
refactor(incentives): remove redundant param from CreateGaugeRefKeys (#…
Browse files Browse the repository at this point in the history
…6511)

* refactor(incentives): remove redundant param from CreateGaugeRefKeys

* update changelog

---------

Co-authored-by: devbot-wizard <[email protected]>
  • Loading branch information
p0mvn and devbot-wizard authored Sep 24, 2023
1 parent 0898499 commit 1e83ec9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### API Breaks

* [#6487](https://github.com/osmosis-labs/osmosis/pull/6487) make PoolModuleI CalculateSpotPrice API return BigDec
* [#6511](https://github.com/osmosis-labs/osmosis/pull/6511) remove redundant param from CreateGaugeRefKeys in incentives
* [#6510](https://github.com/osmosis-labs/osmosis/pull/6510) remove redundant ctx param from DeleteAllKeysFromPrefix in osmoutils

## v19.1.0
Expand Down
18 changes: 9 additions & 9 deletions x/incentives/keeper/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ func (k Keeper) setGauge(ctx sdk.Context, gauge *types.Gauge) error {
// CreateGaugeRefKeys takes combinedKey (the keyPrefix for upcoming, active, or finished gauges combined with gauge start time) and adds a reference to the respective gauge ID.
// If gauge is active or upcoming, creates reference between the denom and gauge ID.
// Used to consolidate codepaths for InitGenesis and CreateGauge.
func (k Keeper) CreateGaugeRefKeys(ctx sdk.Context, gauge *types.Gauge, combinedKeys []byte, activeOrUpcomingGauge bool) error {
func (k Keeper) CreateGaugeRefKeys(ctx sdk.Context, gauge *types.Gauge, combinedKeys []byte) error {
if err := k.addGaugeRefByKey(ctx, combinedKeys, gauge.Id); err != nil {
return err
}

activeOrUpcomingGauge := gauge.IsActiveGauge(ctx.BlockTime()) || gauge.IsUpcomingGauge(ctx.BlockTime())

if activeOrUpcomingGauge {
if err := k.addGaugeIDForDenom(ctx, gauge.Id, gauge.DistributeTo.Denom); err != nil {
return err
Expand All @@ -80,17 +83,16 @@ func (k Keeper) SetGaugeWithRefKey(ctx sdk.Context, gauge *types.Gauge) error {

curTime := ctx.BlockTime()
timeKey := getTimeKey(gauge.StartTime)
activeOrUpcomingGauge := gauge.IsActiveGauge(curTime) || gauge.IsUpcomingGauge(curTime)

if gauge.IsUpcomingGauge(curTime) {
combinedKeys := combineKeys(types.KeyPrefixUpcomingGauges, timeKey)
return k.CreateGaugeRefKeys(ctx, gauge, combinedKeys, activeOrUpcomingGauge)
return k.CreateGaugeRefKeys(ctx, gauge, combinedKeys)
} else if gauge.IsActiveGauge(curTime) {
combinedKeys := combineKeys(types.KeyPrefixActiveGauges, timeKey)
return k.CreateGaugeRefKeys(ctx, gauge, combinedKeys, activeOrUpcomingGauge)
return k.CreateGaugeRefKeys(ctx, gauge, combinedKeys)
} else {
combinedKeys := combineKeys(types.KeyPrefixFinishedGauges, timeKey)
return k.CreateGaugeRefKeys(ctx, gauge, combinedKeys, activeOrUpcomingGauge)
return k.CreateGaugeRefKeys(ctx, gauge, combinedKeys)
}
}

Expand Down Expand Up @@ -198,9 +200,8 @@ func (k Keeper) CreateGauge(ctx sdk.Context, isPerpetual bool, owner sdk.AccAddr
k.SetLastGaugeID(ctx, gauge.Id)

combinedKeys := combineKeys(types.KeyPrefixUpcomingGauges, getTimeKey(gauge.StartTime))
activeOrUpcomingGauge := true

err = k.CreateGaugeRefKeys(ctx, &gauge, combinedKeys, activeOrUpcomingGauge)
err = k.CreateGaugeRefKeys(ctx, &gauge, combinedKeys)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -264,9 +265,8 @@ func (k Keeper) CreateGroup(ctx sdk.Context, coins sdk.Coins, numEpochPaidOver u
// TODO: check if this is necessary.
// Tracked in issue https://github.com/osmosis-labs/osmosis/issues/6405
combinedKeys := combineKeys(types.KeyPrefixUpcomingGauges, getTimeKey(gauge.StartTime))
activeOrUpcomingGauge := true

if err := k.CreateGaugeRefKeys(ctx, &gauge, combinedKeys, activeOrUpcomingGauge); err != nil {
if err := k.CreateGaugeRefKeys(ctx, &gauge, combinedKeys); err != nil {
return 0, err
}
k.hooks.AfterCreateGauge(ctx, gauge.Id)
Expand Down

0 comments on commit 1e83ec9

Please sign in to comment.