-
Notifications
You must be signed in to change notification settings - Fork 574
/
hooks.go
126 lines (101 loc) · 4.04 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package keeper
import (
"time"
"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v23/x/superfluid/keeper/internal/events"
"github.com/osmosis-labs/osmosis/v23/x/superfluid/types"
epochstypes "github.com/osmosis-labs/osmosis/x/epochs/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// 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}
}
// GetModuleName implements types.EpochHooks.
func (Hooks) GetModuleName() string {
return types.ModuleName
}
// epochs hooks
// Don't do anything pre epoch start.
func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
return nil
}
func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
return h.k.AfterEpochEnd(ctx, epochIdentifier, epochNumber)
}
// lockup hooks
// if you add tokens to a lock that is superfluid unbonding, nothing happens superfluid side.
// This lock does as an edge case take on the slashing risk as well for historical slashes.
// This is deemed as fine, governance can re-pay if it occurs on mainnet.
func (h Hooks) AfterAddTokensToLock(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins) {
intermediaryAccAddr := h.k.GetLockIdIntermediaryAccountConnection(ctx, lockID)
if !intermediaryAccAddr.Empty() {
// superfluid delegate for additional amount
err := h.k.IncreaseSuperfluidDelegation(ctx, lockID, amount)
if err != nil {
h.k.Logger(ctx).Error(err.Error())
} else {
events.EmitSuperfluidIncreaseDelegationEvent(ctx, lockID, amount)
}
}
}
func (h Hooks) OnTokenLocked(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time) {
}
func (h Hooks) OnStartUnlock(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time) {
}
func (h Hooks) OnTokenUnlocked(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time) {
}
func (h Hooks) OnTokenSlashed(ctx sdk.Context, lockID uint64, amount sdk.Coins) {
}
func (h Hooks) OnLockupExtend(ctx sdk.Context, lockID uint64, oldDuration, newDuration time.Duration) {
}
// staking hooks.
func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error {
return nil
}
func (h Hooks) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) error {
return nil
}
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
return nil
}
func (h Hooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
return nil
}
func (h Hooks) AfterValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
return nil
}
func (h Hooks) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
}
func (h Hooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
}
func (h Hooks) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
}
func (h Hooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
return nil
}
func (h Hooks) AfterUnbondingInitiated(_ sdk.Context, _ uint64) error {
return nil
}
func (h Hooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, slashFactor osmomath.Dec) error {
if slashFactor.IsZero() {
return nil
}
h.k.SlashLockupsForValidatorSlash(ctx, valAddr, slashFactor)
return nil
}
func (h Hooks) AfterValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, infractionHeight int64, slashFactor osmomath.Dec, effectiveSlashFactor osmomath.Dec) {
if slashFactor.IsZero() {
return
}
accs := h.k.GetAllIntermediaryAccounts(ctx)
h.k.RefreshIntermediaryDelegationAmounts(ctx, accs)
}