From 611eff93cf06428c10c06d108179453170ab848f Mon Sep 17 00:00:00 2001 From: Denali Marsh Date: Wed, 6 May 2020 13:23:13 -0700 Subject: [PATCH] [R4R] Update bep3 module account permissions (#483) * incoming swaps trigger acc registration * move supply increment after recipient acc validation * use expected keepers pattern * remove expected keepers from alias * update bep3 macc permissions * clean supply keeper interface * add module account check to genesis * remove duplicated accountkeeper --- app/app.go | 2 +- x/bep3/genesis.go | 6 ++++++ x/bep3/keeper/keeper.go | 4 ---- x/bep3/types/expected_keepers.go | 4 ---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/app.go b/app/app.go index 4036493d..5dda48b6 100644 --- a/app/app.go +++ b/app/app.go @@ -89,7 +89,7 @@ var ( cdp.ModuleName: {supply.Minter, supply.Burner}, cdp.LiquidatorMacc: {supply.Minter, supply.Burner}, cdp.SavingsRateMacc: {supply.Minter}, - bep3.ModuleName: {supply.Minter, supply.Burner}, + bep3.ModuleName: nil, kavadist.ModuleName: {supply.Minter}, } ) diff --git a/x/bep3/genesis.go b/x/bep3/genesis.go index e3f34694..cd7836b7 100644 --- a/x/bep3/genesis.go +++ b/x/bep3/genesis.go @@ -10,6 +10,12 @@ import ( // InitGenesis initializes the store state from a genesis state. func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, gs GenesisState) { + // Check if the module account exists + moduleAcc := supplyKeeper.GetModuleAccount(ctx, ModuleName) + if moduleAcc == nil { + panic(fmt.Sprintf("%s module account has not been set", ModuleName)) + } + if err := gs.Validate(); err != nil { panic(fmt.Sprintf("failed to validate %s genesis state: %s", ModuleName, err)) } diff --git a/x/bep3/keeper/keeper.go b/x/bep3/keeper/keeper.go index ec1eb9a4..4657138b 100644 --- a/x/bep3/keeper/keeper.go +++ b/x/bep3/keeper/keeper.go @@ -27,10 +27,6 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.SupplyKeeper, ak types.AccountKeeper, paramstore subspace.Subspace, ) Keeper { - if addr := sk.GetModuleAddress(types.ModuleName); addr == nil { - panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) - } - if !paramstore.HasKeyTable() { paramstore = paramstore.WithKeyTable(types.ParamKeyTable()) } diff --git a/x/bep3/types/expected_keepers.go b/x/bep3/types/expected_keepers.go index 13eeb6b6..4035557e 100644 --- a/x/bep3/types/expected_keepers.go +++ b/x/bep3/types/expected_keepers.go @@ -11,12 +11,8 @@ type SupplyKeeper interface { GetModuleAddress(name string) sdk.AccAddress GetModuleAccount(ctx sdk.Context, moduleName string) supplyexported.ModuleAccountI - SendCoinsFromModuleToModule(ctx sdk.Context, sender, recipient string, amt sdk.Coins) error SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - - BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error - MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error } // AccountKeeper defines the expected account keeper (noalias)