-
Notifications
You must be signed in to change notification settings - Fork 44
/
hooks_amm.go
85 lines (72 loc) · 3.12 KB
/
hooks_amm.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
package keeper
import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
ammtypes "github.com/elys-network/elys/x/amm/types"
"github.com/elys-network/elys/x/masterchef/types"
)
// AfterPoolCreated is called after CreatePool
func (k Keeper) AfterPoolCreated(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) {
_, found := k.GetPool(ctx, poolId)
if found {
return
}
// Initiate a new pool info
poolInfo := types.PoolInfo{
// reward amount
PoolId: poolId,
// reward wallet address
RewardWallet: ammtypes.NewPoolRevenueAddress(poolId).String(),
// multiplier for lp rewards
Multiplier: sdk.NewDec(1),
// Eden APR, updated at every distribution
EdenApr: math.LegacyZeroDec(),
// Dex APR, updated at every distribution
DexApr: math.LegacyZeroDec(),
// Gas APR, updated at every distribution
GasApr: math.LegacyZeroDec(),
// External Incentive APR, updated at every distribution
ExternalIncentiveApr: math.LegacyZeroDec(),
// external reward denoms on the pool
ExternalRewardDenoms: []string{},
}
k.SetPool(ctx, poolInfo)
}
// AfterJoinPool is called after JoinPool, JoinSwapExternAmountIn, and JoinSwapShareAmountOut
func (k Keeper) AfterJoinPool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, enterCoins sdk.Coins, shareOutAmount math.Int) {
k.AfterDeposit(ctx, poolId, sender.String(), shareOutAmount)
}
// AfterExitPool is called after ExitPool, ExitSwapShareAmountIn, and ExitSwapExternAmountOut
func (k Keeper) AfterExitPool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, shareInAmount math.Int, exitCoins sdk.Coins) error {
k.AfterWithdraw(ctx, poolId, sender.String(), shareInAmount)
return nil
}
// AfterSwap is called after SwapExactAmountIn and SwapExactAmountOut
func (k Keeper) AfterSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) error {
return nil
}
// Hooks wrapper struct for incentive keeper
type AmmHooks struct {
k Keeper
}
var _ ammtypes.AmmHooks = AmmHooks{}
// Return the wrapper struct
func (k Keeper) AmmHooks() AmmHooks {
return AmmHooks{k}
}
// AfterPoolCreated is called after CreatePool
func (h AmmHooks) AfterPoolCreated(ctx sdk.Context, sender sdk.AccAddress, pool ammtypes.Pool) {
h.k.AfterPoolCreated(ctx, sender, pool.PoolId)
}
// AfterJoinPool is called after JoinPool, JoinSwapExternAmountIn, and JoinSwapShareAmountOut
func (h AmmHooks) AfterJoinPool(ctx sdk.Context, sender sdk.AccAddress, pool ammtypes.Pool, enterCoins sdk.Coins, shareOutAmount math.Int) {
h.k.AfterJoinPool(ctx, sender, pool.PoolId, enterCoins, shareOutAmount)
}
// AfterExitPool is called after ExitPool, ExitSwapShareAmountIn, and ExitSwapExternAmountOut
func (h AmmHooks) AfterExitPool(ctx sdk.Context, sender sdk.AccAddress, pool ammtypes.Pool, shareInAmount math.Int, exitCoins sdk.Coins) error {
return h.k.AfterExitPool(ctx, sender, pool.PoolId, shareInAmount, exitCoins)
}
// AfterSwap is called after SwapExactAmountIn and SwapExactAmountOut
func (h AmmHooks) AfterSwap(ctx sdk.Context, sender sdk.AccAddress, pool ammtypes.Pool, input sdk.Coins, output sdk.Coins) error {
return h.k.AfterSwap(ctx, sender, pool.PoolId, input, output)
}