forked from osmosis-labs/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.go
69 lines (58 loc) · 2.07 KB
/
hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package keeper
import (
epochstypes "github.com/MonOsmosis/osmosis/v10/x/epochs/types"
"github.com/MonOsmosis/osmosis/v10/x/incentives/types"
lockuptypes "github.com/MonOsmosis/osmosis/v10/x/lockup/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) {
}
func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) {
params := k.GetParams(ctx)
if epochIdentifier == params.DistrEpochIdentifier {
// begin distribution if it's start time
gauges := k.GetUpcomingGauges(ctx)
for _, gauge := range gauges {
if !ctx.BlockTime().Before(gauge.StartTime) {
if err := k.moveUpcomingGaugeToActiveGauge(ctx, gauge); err != nil {
panic(err)
}
}
}
// distribute due to epoch event
ctx.EventManager().IncreaseCapacity(2e6)
gauges = k.GetActiveGauges(ctx)
// only distribute to active gauges that are for native denoms
// or non-perpetual and for synthetic denoms.
// We distribute to perpetual synthetic denoms elsewhere in superfluid.
// TODO: This method of doing is a bit of hack, should clean this up later.
distrGauges := []types.Gauge{}
for _, gauge := range gauges {
isSynthetic := lockuptypes.IsSyntheticDenom(gauge.DistributeTo.Denom)
if !(isSynthetic && gauge.IsPerpetual) {
distrGauges = append(distrGauges, gauge)
}
}
_, err := k.Distribute(ctx, distrGauges)
if err != nil {
panic(err)
}
}
}
// ___________________________________________________________________________________________________
// Hooks wrapper struct for incentives keeper.
type Hooks struct {
k Keeper
}
var _ epochstypes.EpochHooks = Hooks{}
// Return the wrapper struct.
func (k Keeper) Hooks() Hooks {
return Hooks{k}
}
// epochs hooks.
func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) {
h.k.BeforeEpochStart(ctx, epochIdentifier, epochNumber)
}
func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) {
h.k.AfterEpochEnd(ctx, epochIdentifier, epochNumber)
}