generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 120
/
keeper.go
112 lines (94 loc) · 3.39 KB
/
keeper.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
package keeper
import (
"context"
"cosmossdk.io/collections"
"cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/axone-protocol/axoned/v8/x/mint/types"
)
// Keeper of the mint store.
type Keeper struct {
cdc codec.BinaryCodec
storeService store.KVStoreService
// the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account.
authority string
stakingKeeper types.StakingKeeper
bankKeeper types.BankKeeper
feeCollectorName string
Schema collections.Schema
Params collections.Item[types.Params]
Minter collections.Item[types.Minter]
}
// NewKeeper creates a new mint Keeper instance.
func NewKeeper(
cdc codec.BinaryCodec,
storeService store.KVStoreService,
sk types.StakingKeeper,
ak types.AccountKeeper,
bk types.BankKeeper,
feeCollectorName string,
authority string,
) Keeper {
// ensure mint module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
panic("the mint module account has not been set")
}
sb := collections.NewSchemaBuilder(storeService)
k := Keeper{
cdc: cdc,
storeService: storeService,
authority: authority,
stakingKeeper: sk,
bankKeeper: bk,
feeCollectorName: feeCollectorName,
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
Minter: collections.NewItem(sb, types.MinterKey, "minter", codec.CollValue[types.Minter](cdc)),
}
schema, err := sb.Build()
if err != nil {
panic(err)
}
k.Schema = schema
return k
}
// GetAuthority returns the x/mint module's authority.
func (keeper Keeper) GetAuthority() string {
return keeper.authority
}
// Logger returns a module-specific logger.
func (keeper Keeper) Logger(ctx context.Context) log.Logger {
sdkCtx := sdk.UnwrapSDKContext(ctx)
return sdkCtx.Logger().With("module", "x/"+types.ModuleName)
}
// TokenSupply implements an alias call to the underlying bank keeper's
// TokenSupply to be used in BeginBlocker.
func (keeper Keeper) TokenSupply(ctx context.Context, denom string) math.Int {
return keeper.bankKeeper.GetSupply(ctx, denom).Amount
}
// StakingTokenSupply implements an alias call to the underlying staking keeper's
// StakingTokenSupply to be used in BeginBlocker.
func (keeper Keeper) StakingTokenSupply(ctx context.Context) (math.Int, error) {
return keeper.stakingKeeper.StakingTokenSupply(ctx)
}
// BondedRatio implements an alias call to the underlying staking keeper's
// BondedRatio to be used in BeginBlocker.
func (keeper Keeper) BondedRatio(ctx context.Context) (math.LegacyDec, error) {
return keeper.stakingKeeper.BondedRatio(ctx)
}
// MintCoins implements an alias call to the underlying supply keeper's
// MintCoins to be used in BeginBlocker.
func (keeper Keeper) MintCoins(ctx context.Context, newCoins sdk.Coins) error {
if newCoins.Empty() {
// skip as no coins need to be minted
return nil
}
return keeper.bankKeeper.MintCoins(ctx, types.ModuleName, newCoins)
}
// AddCollectedFees implements an alias call to the underlying supply keeper's
// AddCollectedFees to be used in BeginBlocker.
func (keeper Keeper) AddCollectedFees(ctx context.Context, fees sdk.Coins) error {
return keeper.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, keeper.feeCollectorName, fees)
}