Skip to content

Commit

Permalink
switch naming from concentrated to NoLock and move duration setup int…
Browse files Browse the repository at this point in the history
…o appropriate logic branch
  • Loading branch information
AlpinYukseloglu committed Jan 29, 2024
1 parent 00b845b commit 34bba93
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions x/incentives/keeper/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func (k Keeper) CreateGauge(ctx sdk.Context, isPerpetual bool, owner sdk.AccAddr
return 0, types.ErrZeroNumEpochsPaidOver
}

// If the gauge has no lock, then we assume it is a concentrated pool and ensure
// the gauge "lock" duration is an authorized uptime.
isConcentratedPoolGauge := distrTo.LockQueryType == lockuptypes.NoLock
// If the gauge has no lock, then we currently assume it is a concentrated pool
// and ensure the gauge "lock" duration is an authorized uptime.
isNoLockGauge := distrTo.LockQueryType == lockuptypes.NoLock

// If the gauge has an internal gauge denom, it is an internal gauge
// and should be run through different validation logic (see below).
Expand All @@ -139,30 +139,30 @@ func (k Keeper) CreateGauge(ctx sdk.Context, isPerpetual bool, owner sdk.AccAddr
// check cannot be controlled by user input.
// 2. The safety of this leans on the special-casing of internal gauge logic during
// distributions, which should be using the internal incentive duration gov param instead of the duration value.
isInternalConcentratedPoolGauge := distrTo.Denom == types.NoLockInternalGaugeDenom(poolId)
isExternalConcentratedPoolGauge := isConcentratedPoolGauge && !isInternalConcentratedPoolGauge

// Ensure that this gauge's duration is one of the allowed durations on chain
// Concentrated pool gauges check against authorized uptimes (if external) or
// epoch duration (if internal).
//
// All other gauges check against the default set of lockable durations.
var durations []time.Duration
if isExternalConcentratedPoolGauge {
durations = k.clk.GetParams(ctx).AuthorizedUptimes
} else if isInternalConcentratedPoolGauge {
// Internal CL gauges use epoch time as their duration. This is a legacy
// property that does not affect the uptime on created records, which is
// determined by the gov param for internal incentive uptimes.
durations = []time.Duration{k.GetEpochInfo(ctx).Duration}
} else {
// This branch is applicable to CFMM pool types such as balancer and stableswap.
durations = k.GetLockableDurations(ctx)
}
isInternalNoLockGauge := isNoLockGauge && distrTo.Denom == types.NoLockInternalGaugeDenom(poolId)
isExternalNoLockGauge := isNoLockGauge && !isInternalNoLockGauge

// We check durations if the gauge is a regular duration based gauge or if it is a
// CL gauge. Note that this excludes time-based gauges and group gauges.
if distrTo.LockQueryType == lockuptypes.ByDuration || isConcentratedPoolGauge {
if isNoLockGauge || distrTo.LockQueryType == lockuptypes.ByDuration {
// Ensure that this gauge's duration is one of the allowed durations on chain
// Concentrated pool gauges check against authorized uptimes (if external) or
// epoch duration (if internal).
//
// All other gauges check against the default set of lockable durations.
var durations []time.Duration
if isExternalNoLockGauge {
durations = k.clk.GetParams(ctx).AuthorizedUptimes
} else if isInternalNoLockGauge {
// Internal CL gauges use epoch time as their duration. This is a legacy
// property that does not affect the uptime on created records, which is
// determined by the gov param for internal incentive uptimes.
durations = []time.Duration{k.GetEpochInfo(ctx).Duration}
} else {
// This branch is applicable to CFMM pool types such as balancer and stableswap.
durations = k.GetLockableDurations(ctx)
}

durationOk := false
for _, duration := range durations {
if duration == distrTo.Duration {
Expand All @@ -179,7 +179,7 @@ func (k Keeper) CreateGauge(ctx sdk.Context, isPerpetual bool, owner sdk.AccAddr

// For no lock gauges, a pool id must be set.
// A pool with such id must exist and be a concentrated pool.
if isConcentratedPoolGauge {
if isNoLockGauge {
if poolId == 0 {
return 0, fmt.Errorf("'no lock' type gauges must have a pool id")
}
Expand All @@ -188,7 +188,7 @@ func (k Keeper) CreateGauge(ctx sdk.Context, isPerpetual bool, owner sdk.AccAddr
// and get overwritten with the external prefix + pool id
// for internal query purposes.
distrToDenom := distrTo.Denom
if !isInternalConcentratedPoolGauge {
if !isInternalNoLockGauge {
// If denom is set, then fails.
if distrToDenom != "" {
return 0, fmt.Errorf("'no lock' type external gauges must have an empty denom set, was %s", distrToDenom)
Expand Down

0 comments on commit 34bba93

Please sign in to comment.