Skip to content

Commit

Permalink
Merge pull request #645 from axone-protocol/refactor/update-mint
Browse files Browse the repository at this point in the history
⬆️ Update mint module to align on latest cosmos-sdk v0.50.6
  • Loading branch information
bdeneux authored May 22, 2024
2 parents 44f1152 + 039a1eb commit 8f3cdb8
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 160 deletions.
2 changes: 1 addition & 1 deletion docs/command/axoned_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ axoned query [flags]
* [axoned query ibc-transfer](axoned_query_ibc-transfer.md) - IBC fungible token transfer query subcommands
* [axoned query interchain-accounts](axoned_query_interchain-accounts.md) - IBC interchain accounts query subcommands
* [axoned query logic](axoned_query_logic.md) - Querying commands for the logic module
* [axoned query mint](axoned_query_mint.md) - Querying commands for the minting module
* [axoned query mint](axoned_query_mint.md) - Querying commands for the mint module
* [axoned query params](axoned_query_params.md) - Querying commands for the params module
* [axoned query slashing](axoned_query_slashing.md) - Querying commands for the slashing module
* [axoned query staking](axoned_query_staking.md) - Querying commands for the staking module
Expand Down
8 changes: 4 additions & 4 deletions docs/command/axoned_query_mint.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## axoned query mint

Querying commands for the minting module
Querying commands for the mint module

```
axoned query mint [flags]
Expand All @@ -15,6 +15,6 @@ axoned query mint [flags]
### SEE ALSO

* [axoned query](axoned_query.md) - Querying subcommands
* [axoned query mint annual-provisions](axoned_query_mint_annual-provisions.md) - Query the current minting annual provisions value
* [axoned query mint inflation](axoned_query_mint_inflation.md) - Query the current minting inflation value
* [axoned query mint params](axoned_query_mint_params.md) - Query the current minting parameters
* [axoned query mint annual-provisions](axoned_query_mint_annual-provisions.md) - Execute the AnnualProvisions RPC method
* [axoned query mint inflation](axoned_query_mint_inflation.md) - Execute the Inflation RPC method
* [axoned query mint params](axoned_query_mint_params.md) - Execute the Params RPC method
5 changes: 3 additions & 2 deletions docs/command/axoned_query_mint_annual-provisions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## axoned query mint annual-provisions

Query the current minting annual provisions value
Execute the AnnualProvisions RPC method

```
axoned query mint annual-provisions [flags]
Expand All @@ -13,10 +13,11 @@ axoned query mint annual-provisions [flags]
--grpc-insecure allow gRPC over insecure channels, if not the server must use TLS
--height int Use a specific height to query state at (this can error if the node is pruning state)
-h, --help help for annual-provisions
--no-indent Do not indent JSON output
--node string <host>:<port> to CometBFT RPC interface for this chain (default "tcp://localhost:26657")
-o, --output string Output format (text|json) (default "text")
```

### SEE ALSO

* [axoned query mint](axoned_query_mint.md) - Querying commands for the minting module
* [axoned query mint](axoned_query_mint.md) - Querying commands for the mint module
5 changes: 3 additions & 2 deletions docs/command/axoned_query_mint_inflation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## axoned query mint inflation

Query the current minting inflation value
Execute the Inflation RPC method

```
axoned query mint inflation [flags]
Expand All @@ -13,10 +13,11 @@ axoned query mint inflation [flags]
--grpc-insecure allow gRPC over insecure channels, if not the server must use TLS
--height int Use a specific height to query state at (this can error if the node is pruning state)
-h, --help help for inflation
--no-indent Do not indent JSON output
--node string <host>:<port> to CometBFT RPC interface for this chain (default "tcp://localhost:26657")
-o, --output string Output format (text|json) (default "text")
```

### SEE ALSO

* [axoned query mint](axoned_query_mint.md) - Querying commands for the minting module
* [axoned query mint](axoned_query_mint.md) - Querying commands for the mint module
5 changes: 3 additions & 2 deletions docs/command/axoned_query_mint_params.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## axoned query mint params

Query the current minting parameters
Execute the Params RPC method

```
axoned query mint params [flags]
Expand All @@ -13,10 +13,11 @@ axoned query mint params [flags]
--grpc-insecure allow gRPC over insecure channels, if not the server must use TLS
--height int Use a specific height to query state at (this can error if the node is pruning state)
-h, --help help for params
--no-indent Do not indent JSON output
--node string <host>:<port> to CometBFT RPC interface for this chain (default "tcp://localhost:26657")
-o, --output string Output format (text|json) (default "text")
```

### SEE ALSO

* [axoned query mint](axoned_query_mint.md) - Querying commands for the minting module
* [axoned query mint](axoned_query_mint.md) - Querying commands for the mint module
12 changes: 6 additions & 6 deletions x/mint/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ import (
)

// InitGenesis new mint genesis.
func (keeper Keeper) InitGenesis(ctx sdk.Context, ak types.AccountKeeper, data *types.GenesisState) {
if err := keeper.Minter.Set(ctx, data.Minter); err != nil {
func (k Keeper) InitGenesis(ctx sdk.Context, ak types.AccountKeeper, data *types.GenesisState) {
if err := k.Minter.Set(ctx, data.Minter); err != nil {
panic(err)
}

if err := keeper.Params.Set(ctx, data.Params); err != nil {
if err := k.Params.Set(ctx, data.Params); err != nil {
panic(err)
}

ak.GetModuleAccount(ctx, types.ModuleName)
}

// ExportGenesis returns a GenesisState for a given context and keeper.
func (keeper Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
minter, err := keeper.Minter.Get(ctx)
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
minter, err := k.Minter.Get(ctx)
if err != nil {
panic(err)
}

params, err := keeper.Params.Get(ctx)
params, err := k.Params.Get(ctx)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/mint/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *GenesisTestSuite) SetupTest() {

func (s *GenesisTestSuite) TestImportExportGenesis() {
genesisState := types.DefaultGenesisState()
genesisState.Minter = types.NewMinter(math.LegacyOneDec(), math.LegacyNewDecWithPrec(20, 2))
genesisState.Minter = types.NewMinter(math.LegacyNewDecWithPrec(20, 2), math.LegacyNewDec(1))
genesisState.Params = types.NewParams(
"testDenom",
math.LegacyNewDecWithPrec(69, 2),
Expand Down
46 changes: 24 additions & 22 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package keeper

import (
"context"
"fmt"

"cosmossdk.io/collections"
"cosmossdk.io/core/store"
storetypes "cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/math"

Expand All @@ -16,14 +17,16 @@ import (

// 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
cdc codec.BinaryCodec
storeService storetypes.KVStoreService
stakingKeeper types.StakingKeeper
bankKeeper types.BankKeeper
feeCollectorName string

// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string

Schema collections.Schema
Params collections.Item[types.Params]
Minter collections.Item[types.Minter]
Expand All @@ -32,7 +35,7 @@ type Keeper struct {
// NewKeeper creates a new mint Keeper instance.
func NewKeeper(
cdc codec.BinaryCodec,
storeService store.KVStoreService,
storeService storetypes.KVStoreService,
sk types.StakingKeeper,
ak types.AccountKeeper,
bk types.BankKeeper,
Expand All @@ -41,17 +44,17 @@ func NewKeeper(
) Keeper {
// ensure mint module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
panic("the mint module account has not been set")
panic(fmt.Sprintf("the x/%s module account has not been set", types.ModuleName))
}

sb := collections.NewSchemaBuilder(storeService)
k := Keeper{
cdc: cdc,
storeService: storeService,
authority: authority,
stakingKeeper: sk,
bankKeeper: bk,
feeCollectorName: feeCollectorName,
authority: authority,
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
Minter: collections.NewItem(sb, types.MinterKey, "minter", codec.CollValue[types.Minter](cdc)),
}
Expand All @@ -61,52 +64,51 @@ func NewKeeper(
panic(err)
}
k.Schema = schema

return k
}

// GetAuthority returns the x/mint module's authority.
func (keeper Keeper) GetAuthority() string {
return keeper.authority
func (k Keeper) GetAuthority() string {
return k.authority
}

// Logger returns a module-specific logger.
func (keeper Keeper) Logger(ctx context.Context) log.Logger {
func (k 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
func (k Keeper) TokenSupply(ctx context.Context, denom string) math.Int {
return k.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)
func (k Keeper) StakingTokenSupply(ctx context.Context) (math.Int, error) {
return k.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)
func (k Keeper) BondedRatio(ctx context.Context) (math.LegacyDec, error) {
return k.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 {
func (k 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)
return k.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)
func (k Keeper) AddCollectedFees(ctx context.Context, fees sdk.Coins) error {
return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, fees)
}
3 changes: 2 additions & 1 deletion x/mint/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestKeeperTestSuite(t *testing.T) {
func (s *IntegrationTestSuite) SetupTest() {
encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{})
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
s.ctx = testCtx.Ctx

Expand All @@ -52,7 +53,7 @@ func (s *IntegrationTestSuite) SetupTest() {

s.mintKeeper = keeper.NewKeeper(
encCfg.Codec,
runtime.NewKVStoreService(key),
storeService,
stakingKeeper,
accountKeeper,
bankKeeper,
Expand Down
15 changes: 7 additions & 8 deletions x/mint/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ import (

var _ types.MsgServer = msgServer{}

// msgServer is a wrapper of Keeper.
type msgServer struct {
Keeper
}

// NewMsgServerImpl returns an implementation of the MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
// NewMsgServerImpl returns an implementation of the x/mint MsgServer interface.
func NewMsgServerImpl(k Keeper) types.MsgServer {
return &msgServer{
Keeper: k,
}
}

// UpdateParams implements the gRPC MsgServer interface. When an UpdateParams
// proposal passes, it updates the module parameters. The update can only be
// performed if the requested authority is the Cosmos SDK governance module
// account.
// UpdateParams updates the params.
func (ms msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if ms.authority != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.authority, msg.Authority)
Expand Down
Loading

0 comments on commit 8f3cdb8

Please sign in to comment.