-
Notifications
You must be signed in to change notification settings - Fork 576
/
listeners.go
86 lines (67 loc) · 2.76 KB
/
listeners.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
package twap
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/osmosis/osmomath"
concentratedliquiditytypes "github.com/osmosis-labs/osmosis/v20/x/concentrated-liquidity/types"
gammtypes "github.com/osmosis-labs/osmosis/v20/x/gamm/types"
epochtypes "github.com/osmosis-labs/osmosis/x/epochs/types"
)
var (
_ gammtypes.GammHooks = &gammhook{}
_ epochtypes.EpochHooks = &epochhook{}
)
type epochhook struct {
k Keeper
}
func (k Keeper) EpochHooks() epochtypes.EpochHooks {
return &epochhook{k}
}
func (hook *epochhook) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
if epochIdentifier == hook.k.PruneEpochIdentifier(ctx) {
if err := hook.k.pruneRecords(ctx); err != nil {
ctx.Logger().Error("Error pruning old twaps at the epoch end", err)
}
}
return nil
}
func (hook *epochhook) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
return nil
}
type gammhook struct {
k Keeper
}
func (k Keeper) GammHooks() gammtypes.GammHooks {
return &gammhook{k}
}
// AfterCFMMPoolCreated is called after CreatePool run on a CFMM pool from x/gamm.
func (hook *gammhook) AfterCFMMPoolCreated(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) {
hook.k.mustTrackCreatedPool(ctx, poolId)
}
// AfterCFMMSwap is called after SwapExactAmountIn and SwapExactAmountOut in x/gamm.
func (hook *gammhook) AfterCFMMSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) {
hook.k.trackChangedPool(ctx, poolId)
}
func (hook *gammhook) AfterJoinPool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, enterCoins sdk.Coins, shareOutAmount osmomath.Int) {
hook.k.trackChangedPool(ctx, poolId)
}
func (hook *gammhook) AfterExitPool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, shareInAmount osmomath.Int, exitCoins sdk.Coins) {
hook.k.trackChangedPool(ctx, poolId)
}
type concentratedLiquidityListener struct {
k Keeper
}
func (k Keeper) ConcentratedLiquidityListener() concentratedliquiditytypes.ConcentratedLiquidityListener {
return &concentratedLiquidityListener{k}
}
func (l *concentratedLiquidityListener) AfterConcentratedPoolCreated(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) {
l.k.mustTrackCreatedPool(ctx, poolId)
}
func (l *concentratedLiquidityListener) AfterInitialPoolPositionCreated(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) {
l.k.trackChangedPool(ctx, poolId)
}
func (l *concentratedLiquidityListener) AfterLastPoolPositionRemoved(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) {
l.k.trackChangedPool(ctx, poolId)
}
func (l *concentratedLiquidityListener) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) {
l.k.trackChangedPool(ctx, poolId)
}