/
hooks.go
89 lines (76 loc) · 2.88 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
package keeper
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
epochtypes "github.com/persistenceOne/persistence-sdk/v2/x/epochs/types"
liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"
"github.com/persistenceOne/pstake-native/v2/x/ratesync/types"
)
// Wrapper struct
type LiquidStakeIBCHooks struct {
k Keeper
}
var _ liquidstakeibctypes.LiquidStakeIBCHooks = LiquidStakeIBCHooks{}
// Create new lsibc hooks
func (k Keeper) LiquidStakeIBCHooks() LiquidStakeIBCHooks {
return LiquidStakeIBCHooks{k}
}
func (h LiquidStakeIBCHooks) PostCValueUpdate(ctx sdk.Context, mintDenom, hostDenom string, cValue sdk.Dec) error {
h.k.Logger(ctx).Info("called ratesync hook for PostCValueUpdate")
return h.k.PostCValueUpdate(ctx, mintDenom, hostDenom, cValue)
}
func (k Keeper) PostCValueUpdate(ctx sdk.Context, mintDenom, hostDenom string, cValue sdk.Dec) error {
hcs := k.GetAllHostChain(ctx)
for _, hc := range hcs {
if hc.Features.LiquidStakeIBC.Enabled {
err := k.ExecuteLiquidStakeRateTx(ctx, hc.Features.LiquidStakeIBC, mintDenom, hostDenom, cValue, hc.ID, hc.ConnectionID, hc.ICAAccount)
if err != nil {
k.Logger(ctx).Error("cannot ExecuteLiquidStakeRateTx for host chain ",
"id", hc.ID,
"mint-denom", mintDenom,
"err:", err)
}
}
}
return nil
}
// Wrapper struct
type EpochHooks struct {
k Keeper
}
var _ epochtypes.EpochHooks = EpochHooks{}
// Create new epoch hooks
func (k Keeper) EpochHooks() EpochHooks {
return EpochHooks{k}
}
func (e EpochHooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
e.k.Logger(ctx).Info("called ratesync hook for AfterEpochEnd")
return e.k.AfterEpochEnd(ctx, epochIdentifier, epochNumber)
}
func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
nas := k.liquidStakeKeeper.GetNetAmountState(ctx)
liquidBondDenom := k.liquidStakeKeeper.LiquidBondDenom(ctx)
bondDenom, found := liquidstakeibctypes.MintDenomToHostDenom(liquidBondDenom)
if !found {
return errorsmod.Wrapf(sdkerrors.ErrNotFound, "bondDenom could not be derived from host denom")
}
hcs := k.GetAllHostChain(ctx)
for _, hc := range hcs {
if hc.Features.LiquidStake.Enabled && epochIdentifier == types.LiquidStakeEpoch {
// Add liquidstakekeeper and do stuff
err := k.ExecuteLiquidStakeRateTx(ctx, hc.Features.LiquidStake, liquidBondDenom, bondDenom, nas.MintRate, hc.ID, hc.ConnectionID, hc.ICAAccount)
if err != nil {
k.Logger(ctx).Error("cannot ExecuteLiquidStakeRateTx for host chain ",
"id", hc.ID,
"mint-denom", liquidBondDenom,
"err:", err)
}
}
}
return nil
}
func (e EpochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
e.k.Logger(ctx).Info("called ratesync hook for BeforeEpochStart")
return nil
}