Skip to content

Commit

Permalink
feat(bank/v2): create module boilerplate (#21559)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Sep 6, 2024
1 parent dce0365 commit c7c3fa7
Show file tree
Hide file tree
Showing 36 changed files with 2,785 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
/x/auth/ @facundomedica @testinginprod @aaronc @cosmos/sdk-core-dev
/x/authz/ @akhilkumarpilli @raynaudoe @cosmos/sdk-core-dev
/x/bank/ @julienrbrt @sontrinh16 @cosmos/sdk-core-dev
/x/bank/v2 @julienrbrt @hieuvubk @akhilkumarpilli @cosmos/sdk-core-dev
/x/circuit/ @kocubinski @akhilkumarpilli @raynaudoe @cosmos/sdk-core-dev
/x/consensus/ @testinginprod @raynaudoe @cosmos/sdk-core-dev
/x/distribution/ @alpe @JulianToledano @cosmos/sdk-core-dev
Expand Down
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ updates:
labels:
- "A:automerge"
- dependencies
- package-ecosystem: gomod
directory: "/x/bank"
schedule:
interval: weekly
day: wednesday
time: "03:20"
labels:
- "A:automerge"
- dependencies

# Dependencies should be up to date on release branch
- package-ecosystem: gomod
Expand Down
2 changes: 2 additions & 0 deletions .github/pr_labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
- x/authz/**/*
"C:x/bank":
- x/bank/**/*
"C:x/bank/v2":
- x/bank/v2/**/*
"C:x/circuit":
- x/circuit/**/*
"C:x/consensus":
Expand Down
5 changes: 5 additions & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ done
cp -r github.com/cosmos/cosmos-sdk/* ./
rm -rf github.com

# UNTIL WE FIGURE OUT ABOUT COSMOSSDK.IO/API, DO NOT GENERATE PULSAR FILES FOR NEW MODULES
# unfortunately, there is no way to do it nicely directly in the buf.gen.pulsar.yaml file (https://github.com/bufbuild/buf/issues/224)
rm -r api/cosmos/bank/v2
rm -r api/cosmos/bank/module/v2

go mod tidy
12 changes: 7 additions & 5 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import (
_ "cosmossdk.io/x/authz/module" // import for side-effects
_ "cosmossdk.io/x/bank" // import for side-effects
banktypes "cosmossdk.io/x/bank/types"
_ "cosmossdk.io/x/bank/v2" // import for side-effects
bankv2types "cosmossdk.io/x/bank/v2/types"
bankmodulev2 "cosmossdk.io/x/bank/v2/types/module"
_ "cosmossdk.io/x/circuit" // import for side-effects
circuittypes "cosmossdk.io/x/circuit/types"
_ "cosmossdk.io/x/consensus" // import for side-effects
Expand Down Expand Up @@ -66,8 +69,7 @@ import (

"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/testutil/x/counter" // import for side-effects
countertypes "github.com/cosmos/cosmos-sdk/testutil/x/counter/types"
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import for side-effects
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
Expand Down Expand Up @@ -153,6 +155,7 @@ var (
accounts.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
bankv2types.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
Expand Down Expand Up @@ -284,10 +287,9 @@ var (
Name: epochstypes.ModuleName,
Config: appconfig.WrapAny(&epochsmodulev1.Module{}),
},
// This module is only used for testing the depinject gogo x pulsar module registration.
{
Name: countertypes.ModuleName,
Config: appconfig.WrapAny(&countertypes.Module{}),
Name: bankv2types.ModuleName,
Config: appconfig.WrapAny(&bankmodulev2.Module{}),
},
},
})
Expand Down
3 changes: 3 additions & 0 deletions simapp/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"cosmossdk.io/x/accounts"
authzkeeper "cosmossdk.io/x/authz/keeper"
bankkeeper "cosmossdk.io/x/bank/keeper"
bankv2keeper "cosmossdk.io/x/bank/v2/keeper"
circuitkeeper "cosmossdk.io/x/circuit/keeper"
consensuskeeper "cosmossdk.io/x/consensus/keeper"
distrkeeper "cosmossdk.io/x/distribution/keeper"
Expand Down Expand Up @@ -74,6 +75,7 @@ type SimApp struct {
AccountsKeeper accounts.Keeper
AuthKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
BankV2Keeper *bankv2keeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
Expand Down Expand Up @@ -184,6 +186,7 @@ func NewSimApp(
&app.AuthKeeper,
&app.AccountsKeeper,
&app.BankKeeper,
&app.BankV2Keeper,
&app.StakingKeeper,
&app.SlashingKeeper,
&app.MintKeeper,
Expand Down
2 changes: 2 additions & 0 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
authzmodule "cosmossdk.io/x/authz/module"
"cosmossdk.io/x/bank"
banktypes "cosmossdk.io/x/bank/types"
bankv2 "cosmossdk.io/x/bank/v2"
"cosmossdk.io/x/distribution"
"cosmossdk.io/x/epochs"
"cosmossdk.io/x/evidence"
Expand Down Expand Up @@ -201,6 +202,7 @@ func TestRunMigrations(t *testing.T) {
appmodule.VersionMap{
"accounts": accounts.AppModule{}.ConsensusVersion(),
"bank": 1,
"bankv2": bankv2.AppModule{}.ConsensusVersion(),
"auth": auth.AppModule{}.ConsensusVersion(),
"authz": authzmodule.AppModule{}.ConsensusVersion(),
"staking": staking.AppModule{}.ConsensusVersion(),
Expand Down
4 changes: 2 additions & 2 deletions simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"cosmossdk.io/core/appmodule"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/x/accounts"
bankv2types "cosmossdk.io/x/bank/v2/types"
epochstypes "cosmossdk.io/x/epochs/types"
protocolpooltypes "cosmossdk.io/x/protocolpool/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

countertypes "github.com/cosmos/cosmos-sdk/testutil/x/counter/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
)

Expand Down Expand Up @@ -47,7 +47,7 @@ func (app SimApp) RegisterUpgradeHandlers() {
accounts.StoreKey,
protocolpooltypes.StoreKey,
epochstypes.StoreKey,
countertypes.StoreKey, // This module is used for testing purposes only.
bankv2types.ModuleName,
},
Deleted: []string{"crisis"}, // The SDK discontinued the crisis module in v0.52.0
}
Expand Down
8 changes: 8 additions & 0 deletions simapp/v2/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import (
_ "cosmossdk.io/x/authz/module" // import for side-effects
_ "cosmossdk.io/x/bank" // import for side-effects
banktypes "cosmossdk.io/x/bank/types"
_ "cosmossdk.io/x/bank/v2" // import for side-effects
bankv2types "cosmossdk.io/x/bank/v2/types"
bankmodulev2 "cosmossdk.io/x/bank/v2/types/module"
_ "cosmossdk.io/x/circuit" // import for side-effects
circuittypes "cosmossdk.io/x/circuit/types"
_ "cosmossdk.io/x/consensus" // import for side-effects
Expand Down Expand Up @@ -151,6 +154,7 @@ var (
accounts.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
bankv2types.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
Expand Down Expand Up @@ -283,6 +287,10 @@ var (
Name: epochstypes.ModuleName,
Config: appconfig.WrapAny(&epochsmodulev1.Module{}),
},
{
Name: bankv2types.ModuleName,
Config: appconfig.WrapAny(&bankmodulev2.Module{}),
},
},
})
)
3 changes: 3 additions & 0 deletions simapp/v2/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"cosmossdk.io/x/accounts"
authzkeeper "cosmossdk.io/x/authz/keeper"
bankkeeper "cosmossdk.io/x/bank/keeper"
bankv2keeper "cosmossdk.io/x/bank/v2/keeper"
circuitkeeper "cosmossdk.io/x/circuit/keeper"
consensuskeeper "cosmossdk.io/x/consensus/keeper"
distrkeeper "cosmossdk.io/x/distribution/keeper"
Expand Down Expand Up @@ -56,6 +57,7 @@ type SimApp[T transaction.Tx] struct {
AccountsKeeper accounts.Keeper
AuthKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
BankV2Keeper *bankv2keeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
Expand Down Expand Up @@ -165,6 +167,7 @@ func NewSimApp[T transaction.Tx](
&app.interfaceRegistry,
&app.AuthKeeper,
&app.BankKeeper,
&app.BankV2Keeper,
&app.StakingKeeper,
&app.SlashingKeeper,
&app.MintKeeper,
Expand Down
8 changes: 6 additions & 2 deletions simapp/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
"cosmossdk.io/x/accounts"
bankv2types "cosmossdk.io/x/bank/v2/types"
epochstypes "cosmossdk.io/x/epochs/types"
protocolpooltypes "cosmossdk.io/x/protocolpool/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
)
Expand Down Expand Up @@ -34,8 +36,10 @@ func (app *SimApp[T]) RegisterUpgradeHandlers() {
if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := store.StoreUpgrades{
Added: []string{
accounts.ModuleName,
protocolpooltypes.ModuleName,
accounts.StoreKey,
protocolpooltypes.StoreKey,
epochstypes.StoreKey,
bankv2types.ModuleName,
},
Deleted: []string{"crisis"}, // The SDK discontinued the crisis module in v0.52.0
}
Expand Down
3 changes: 2 additions & 1 deletion x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Here are some production-grade modules that can be used in Cosmos SDK applicatio
* [Auth](./auth/README.md) - Authentication of accounts and transactions for Cosmos SDK applications.
* [Authz](./authz/README.md) - Authorization for accounts to perform actions on behalf of other accounts.
* [Bank](./bank/README.md) - Token transfer functionalities.
* [Bank v2](./bank/v2/README.md) - Token transfer functionalities, enhanced.
* [Circuit](./circuit/README.md) - Circuit breaker module for pausing messages.
* [Consensus](./consensus/README.md) - Consensus module for modifying CometBFT's ABCI consensus params.
* [Distribution](./distribution/README.md) - Fee distribution, and staking token provision distribution.
Expand All @@ -23,7 +24,7 @@ Here are some production-grade modules that can be used in Cosmos SDK applicatio
* [Protocolpool](./protocolpool/README.md) - Functionalities handling community pool funds.
* [Slashing](./slashing/README.md) - Validator punishment mechanisms.
* [Staking](./staking/README.md) - Proof-of-Stake layer for public blockchains.
* [tx](./tx/README.md) - Tx utilities for the Cosmos SDK.
* [Tx](./tx/README.md) - Tx utilities for the Cosmos SDK.
* [Upgrade](./upgrade/README.md) - Software upgrades handling and coordination.

To learn more about the process of building modules, visit the [building modules reference documentation](https://docs.cosmos.network/main/building-modules/intro).
Expand Down
17 changes: 17 additions & 0 deletions x/bank/proto/cosmos/bank/module/v2/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";

package cosmos.bank.module.v2;

import "cosmos/app/v1alpha1/module.proto";

option go_package = "cosmossdk.io/x/bank/v2/types/module";

// Module is the config object of the bank module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "cosmossdk.io/x/bank/v2"
};

// authority defines the custom module authority. If not set, defaults to the governance module.
string authority = 1;
}
7 changes: 7 additions & 0 deletions x/bank/proto/cosmos/bank/v2/bank.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package cosmos.bank.v2;

option go_package = "cosmossdk.io/x/bank/v2/types";

// Params defines the parameters for the bank/v2 module.
message Params {}
14 changes: 14 additions & 0 deletions x/bank/proto/cosmos/bank/v2/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package cosmos.bank.v2;

import "gogoproto/gogo.proto";
import "cosmos/bank/v2/bank.proto";
import "amino/amino.proto";

option go_package = "cosmossdk.io/x/bank/v2/types";

// GenesisState defines the bank/v2 module's genesis state.
message GenesisState {
// params defines all the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
28 changes: 28 additions & 0 deletions x/bank/proto/cosmos/bank/v2/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";
package cosmos.bank.v2;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/query/v1/query.proto";
import "amino/amino.proto";
import "cosmos/bank/v2/bank.proto";

option go_package = "cosmossdk.io/x/bank/v2/types";

// Query defines the gRPC querier service.
service Query {
// Params queries the parameters of x/bank module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/cosmos/bank/v2/params";
}
}

// QueryParamsRequest defines the request type for querying x/bank/v2 parameters.
message QueryParamsRequest {}

// QueryParamsResponse defines the response type for querying x/bank/v2 parameters.
message QueryParamsResponse {
// params provides the parameters of the bank module.
Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
35 changes: 35 additions & 0 deletions x/bank/proto/cosmos/bank/v2/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
syntax = "proto3";
package cosmos.bank.v2;

import "gogoproto/gogo.proto";
import "cosmos/bank/v2/bank.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";

option go_package = "cosmossdk.io/x/bank/v2/types";

// Msg defines the bank Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// UpdateParams defines a governance operation for updating the x/bank/v2 module parameters.
// The authority is defined in the keeper.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) {}
}

// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "cosmos-sdk/x/bank/v2/MsgUpdateParams";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/bank parameters to update.
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgUpdateParamsResponse defines the response structure for executing a MsgUpdateParams message.
message MsgUpdateParamsResponse {}
26 changes: 26 additions & 0 deletions x/bank/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
Guiding Principles:
Changelogs are for humans, not machines.
There should be an entry for every single version.
The same types of changes should be grouped.
Versions and sections should be linkable.
The latest version comes first.
The release date of each version is displayed.
Mention whether you follow Semantic Versioning.
Usage:
Change log entries are to be added to the Unreleased section under the
appropriate stanza (see below). Each entry should ideally include a tag and
the Github issue reference in the following format:
* (<tag>) [#<issue-number>] Changelog message.
Types of changes (Stanzas):
"Features" for new features.
"Improvements" for changes in existing functionality.
"Deprecated" for soon-to-be removed features.
"Bug Fixes" for any bug fixes.
"API Breaking" for breaking exported APIs used by developers building on SDK.
Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog

## [Unreleased]
5 changes: 5 additions & 0 deletions x/bank/v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
sidebar_position: 1
---

# `x/bank/v2`
Loading

0 comments on commit c7c3fa7

Please sign in to comment.