Skip to content

Commit

Permalink
feat(x/photon): mint photon message (#53)
Browse files Browse the repository at this point in the history
Relates to #44

This PR adds a new message `MsgMintPhoton` inside a new `x/photon`
module.
List of changes:
- `x/photon` queries : `params` & `conversion_rate`
- `x/photon` transaction: `MsgMintPhoton`
- app plumbing with the new module
- Some relative changes were made to the e2e tests to remove anything
related to the `stake` denom (use `uatone` instead), which had some
impact on other tests that had to be fixed.
- Makefile:
- target `start-localnet-ci` use `uatone` denom instead of default
`stake`
- new target `mockgen` to generates the mocks from gov and photon
expected keepers

---------

Co-authored-by: Giuseppe Natale <[email protected]>
  • Loading branch information
tbruyelle and giunatale authored Nov 29, 2024
1 parent 1b5576f commit 8ecfade
Show file tree
Hide file tree
Showing 75 changed files with 5,550 additions and 180 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ docker-build-hermes:

docker-build-all: docker-build-debug docker-build-hermes

.PHONY: docker-build-debug docker-build-hermes docker-build-all
mockgen_cmd=$(rundep) github.com/golang/mock/mockgen

mocks-gen:
$(mockgen_cmd) -source=x/gov/testutil/expected_keepers.go -package testutil -destination x/gov/testutil/expected_keepers_mocks.go
$(mockgen_cmd) -source=x/photon/types/expected_keepers.go -package testutil -destination x/photon/testutil/expected_keepers_mocks.go

.PHONY: docker-build-debug docker-build-hermes docker-build-all mocks-gen

###############################################################################
### Linting ###
Expand Down Expand Up @@ -258,14 +264,16 @@ update-swagger-docs: proto-swagger-gen

start-localnet-ci: build
rm -rf ~/.atomoned-liveness
./build/atomoned init liveness --chain-id liveness --home ~/.atomoned-liveness
./build/atomoned init liveness --default-denom uatone --chain-id liveness --home ~/.atomoned-liveness
./build/atomoned config chain-id liveness --home ~/.atomoned-liveness
./build/atomoned config keyring-backend test --home ~/.atomoned-liveness
./build/atomoned keys add val --home ~/.atomoned-liveness
./build/atomoned genesis add-genesis-account val 10000000000000000000000000stake --home ~/.atomoned-liveness --keyring-backend test
./build/atomoned genesis gentx val 1000000000stake --home ~/.atomoned-liveness --chain-id liveness
./build/atomoned genesis add-genesis-account val 1000000000000uatone --home ~/.atomoned-liveness --keyring-backend test
./build/atomoned keys add user --home ~/.atomoned-liveness
./build/atomoned genesis add-genesis-account user 1000000000uatone --home ~/.atomoned-liveness --keyring-backend test
./build/atomoned genesis gentx val 1000000000uatone --home ~/.atomoned-liveness --chain-id liveness
./build/atomoned genesis collect-gentxs --home ~/.atomoned-liveness
sed -i.bak'' 's/minimum-gas-prices = ""/minimum-gas-prices = "0uatone"/' ~/.atomoned-liveness/config/app.toml
sed -i.bak'' 's/minimum-gas-prices = ""/minimum-gas-prices = "0.001uatone,0.001uphoton"/' ~/.atomoned-liveness/config/app.toml
./build/atomoned start --home ~/.atomoned-liveness --x-crisis-skip-assert-invariants

.PHONY: start-localnet-ci
Expand Down
8 changes: 7 additions & 1 deletion ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

atomoneerrors "github.com/atomone-hub/atomone/types/errors"
photonante "github.com/atomone-hub/atomone/x/photon/ante"
photonkeeper "github.com/atomone-hub/atomone/x/photon/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
Expand All @@ -21,6 +23,7 @@ type HandlerOptions struct {
Codec codec.BinaryCodec
IBCkeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
PhotonKeeper *photonkeeper.Keeper
TxFeeChecker ante.TxFeeChecker
}

Expand All @@ -37,10 +40,12 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
if opts.IBCkeeper == nil {
return nil, errorsmod.Wrap(atomoneerrors.ErrLogic, "IBC keeper is required for AnteHandler")
}

if opts.StakingKeeper == nil {
return nil, errorsmod.Wrap(atomoneerrors.ErrNotFound, "staking param store is required for AnteHandler")
}
if opts.PhotonKeeper == nil {
return nil, errorsmod.Wrap(atomoneerrors.ErrNotFound, "photon keeper is required for AnteHandler")
}

sigGasConsumer := opts.SigGasConsumer
if sigGasConsumer == nil {
Expand All @@ -54,6 +59,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
ante.NewValidateMemoDecorator(opts.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
NewGovVoteDecorator(opts.Codec, opts.StakingKeeper),
photonante.NewValidateFeeDecorator(opts.PhotonKeeper),
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker),
ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(opts.AccountKeeper),
Expand Down
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ import (
"github.com/atomone-hub/atomone/app/keepers"
"github.com/atomone-hub/atomone/app/params"
"github.com/atomone-hub/atomone/app/upgrades"
v2 "github.com/atomone-hub/atomone/app/upgrades/v2"
govtypes "github.com/atomone-hub/atomone/x/gov/types"
)

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

Upgrades = []upgrades.Upgrade{}
Upgrades = []upgrades.Upgrade{v2.Upgrade}
)

var (
Expand Down Expand Up @@ -221,6 +222,7 @@ func NewAtomOneApp(
Codec: appCodec,
IBCkeeper: app.IBCKeeper,
StakingKeeper: app.StakingKeeper,
PhotonKeeper: app.PhotonKeeper,
// If TxFeeChecker is nil the default ante TxFeeChecker is used
TxFeeChecker: nil,
},
Expand Down
12 changes: 12 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import (
govtypes "github.com/atomone-hub/atomone/x/gov/types"
govv1 "github.com/atomone-hub/atomone/x/gov/types/v1"
govv1beta1 "github.com/atomone-hub/atomone/x/gov/types/v1beta1"
photonkeeper "github.com/atomone-hub/atomone/x/photon/keeper"
photontypes "github.com/atomone-hub/atomone/x/photon/types"
)

type AppKeepers struct {
Expand Down Expand Up @@ -90,6 +92,7 @@ type AppKeepers struct {
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
PhotonKeeper *photonkeeper.Keeper

// Modules
ICAModule ica.AppModule
Expand Down Expand Up @@ -208,6 +211,15 @@ func NewAppKeeper(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.PhotonKeeper = photonkeeper.NewKeeper(
appCodec,
appKeepers.keys[photontypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appKeepers.BankKeeper,
appKeepers.AccountKeeper,
appKeepers.StakingKeeper,
)

appKeepers.MintKeeper = mintkeeper.NewKeeper(
appCodec,
appKeepers.keys[minttypes.StoreKey],
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

govtypes "github.com/atomone-hub/atomone/x/gov/types"
photontypes "github.com/atomone-hub/atomone/x/photon/types"
)

func (appKeepers *AppKeepers) GenerateKeys() {
Expand All @@ -47,6 +48,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
feegrant.StoreKey,
authzkeeper.StoreKey,
consensusparamtypes.StoreKey,
photontypes.StoreKey,
)

// Define transient store keys
Expand Down
12 changes: 10 additions & 2 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import (
"github.com/atomone-hub/atomone/x/gov"
govclient "github.com/atomone-hub/atomone/x/gov/client"
govtypes "github.com/atomone-hub/atomone/x/gov/types"
"github.com/atomone-hub/atomone/x/photon"
photontypes "github.com/atomone-hub/atomone/x/photon/types"
)

var maccPerms = map[string][]string{
Expand All @@ -58,8 +60,8 @@ var maccPerms = map[string][]string{
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
// liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
photontypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
Expand All @@ -85,6 +87,7 @@ var ModuleBasics = module.NewBasicManager(
sdkparams.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
photon.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
authzmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
Expand Down Expand Up @@ -121,6 +124,7 @@ func appModules(
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
photon.NewAppModule(appCodec, *app.PhotonKeeper, app.BankKeeper, app.AccountKeeper, app.StakingKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -150,6 +154,7 @@ func simulationModules(
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
photon.NewAppModule(appCodec, *app.PhotonKeeper, app.BankKeeper, app.AccountKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
sdkparams.NewAppModule(app.ParamsKeeper),
Expand Down Expand Up @@ -185,6 +190,7 @@ func orderBeginBlockers() []string {
stakingtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
photontypes.ModuleName,
govtypes.ModuleName,
crisistypes.ModuleName,
ibcexported.ModuleName,
Expand Down Expand Up @@ -218,6 +224,7 @@ func orderEndBlockers() []string {
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
photontypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
minttypes.ModuleName,
Expand Down Expand Up @@ -248,6 +255,7 @@ func orderInitBlockers() []string {
distrtypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
photontypes.ModuleName,
slashingtypes.ModuleName,
minttypes.ModuleName,
crisistypes.ModuleName,
Expand Down
20 changes: 20 additions & 0 deletions app/params/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package params

const (
BondDenom = "uatone"

Bech32PrefixAccAddr = "atone"
)

var (
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key.
Bech32PrefixAccPub = Bech32PrefixAccAddr + "pub"
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address.
Bech32PrefixValAddr = Bech32PrefixAccAddr + "valoper"
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key.
Bech32PrefixValPub = Bech32PrefixAccAddr + "valoperpub"
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address.
Bech32PrefixConsAddr = Bech32PrefixAccAddr + "valcons"
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key.
Bech32PrefixConsPub = Bech32PrefixAccAddr + "valconspub"
)
7 changes: 0 additions & 7 deletions app/params/params.go

This file was deleted.

23 changes: 23 additions & 0 deletions app/upgrades/v2/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package v2

import (
store "github.com/cosmos/cosmos-sdk/store/types"

"github.com/atomone-hub/atomone/app/upgrades"
photontypes "github.com/atomone-hub/atomone/x/photon/types"
)

const (
UpgradeName = "v2"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
// new module added in v2
photontypes.ModuleName,
},
},
}
66 changes: 66 additions & 0 deletions app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package v2

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/atomone-hub/atomone/app/keepers"
)

// CreateUpgradeHandler returns a upgrade handler for AtomOne v2
// which executes the following migrations:
// - add new denom metadata for photon in the bank module store.
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting module migrations...")
// RunMigrations will detect the add of the photon module, will initiate
// its genesis and will fill the versionMap with its consensus version.
vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}
// Add the photon denom metadata to the bank module store
setPhotonDenomMetadata(ctx, keepers.BankKeeper)
ctx.Logger().Info("Upgrade complete")
return vm, nil
}
}

func setPhotonDenomMetadata(ctx sdk.Context, bk bankkeeper.Keeper) {
ctx.Logger().Info("Adding photon denom metadata...")
bk.SetDenomMetaData(ctx, banktypes.Metadata{
Base: "uphoton",
Display: "photon",
Name: "AtomOne Photon",
Symbol: "PHOTON",
Description: "The fee token of AtomOne Hub",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: "uphoton",
Exponent: 0,
Aliases: []string{
"microphoton",
},
},
{
Denom: "mphoton",
Exponent: 3,
Aliases: []string{
"milliphoton",
},
},
{
Denom: "photon",
Exponent: 6,
},
},
})
ctx.Logger().Info("Photon denom metadata added")
}
3 changes: 2 additions & 1 deletion cmd/atomoned/cmd/bech32_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

appparams "github.com/atomone-hub/atomone/app/params"
addressutil "github.com/atomone-hub/atomone/pkg/address"
)

Expand Down Expand Up @@ -41,7 +42,7 @@ Example:
},
}

cmd.Flags().StringP(flagBech32Prefix, "p", "atone", "Bech32 Prefix to encode to")
cmd.Flags().StringP(flagBech32Prefix, "p", appparams.Bech32PrefixAccAddr, "Bech32 Prefix to encode to")

return cmd
}
Expand Down
23 changes: 4 additions & 19 deletions cmd/atomoned/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,14 @@ package cmd

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
Bech32PrefixAccAddr = "atone"
)

var (
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key.
Bech32PrefixAccPub = Bech32PrefixAccAddr + "pub"
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address.
Bech32PrefixValAddr = Bech32PrefixAccAddr + "valoper"
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key.
Bech32PrefixValPub = Bech32PrefixAccAddr + "valoperpub"
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address.
Bech32PrefixConsAddr = Bech32PrefixAccAddr + "valcons"
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key.
Bech32PrefixConsPub = Bech32PrefixAccAddr + "valconspub"
appparams "github.com/atomone-hub/atomone/app/params"
)

func InitSDKConfig() {
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
cfg.SetBech32PrefixForAccount(appparams.Bech32PrefixAccAddr, appparams.Bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(appparams.Bech32PrefixValAddr, appparams.Bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(appparams.Bech32PrefixConsAddr, appparams.Bech32PrefixConsPub)
cfg.Seal()
}
1 change: 1 addition & 0 deletions contrib/devdeps/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/atomone-hub/atomone/contrib/devdeps
go 1.21

require (
github.com/golang/mock v1.6.0
github.com/golangci/golangci-lint v1.56.0
github.com/goreleaser/goreleaser v1.25.1
github.com/rakyll/statik v0.1.7
Expand Down
Loading

0 comments on commit 8ecfade

Please sign in to comment.