Skip to content

Commit

Permalink
[CORE-673] - Remove extraneous authtypes.NewModuleAddress, consolidat…
Browse files Browse the repository at this point in the history
…e constants (#641)
  • Loading branch information
clemire committed Oct 25, 2023
1 parent 1fa21ed commit 9b416b3
Show file tree
Hide file tree
Showing 78 changed files with 389 additions and 342 deletions.
10 changes: 5 additions & 5 deletions protocol/app/ante_whitebox_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"github.com/dydxprotocol/v4-chain/protocol/lib"
"reflect"
"testing"

Expand All @@ -14,7 +15,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
libante "github.com/dydxprotocol/v4-chain/protocol/lib/ante"
clobante "github.com/dydxprotocol/v4-chain/protocol/x/clob/ante"
"github.com/dydxprotocol/v4-chain/protocol/x/clob/flags"
Expand All @@ -35,15 +35,15 @@ func newTestHandlerOptions() HandlerOptions {
authtypes.ProtoBaseAccount,
nil,
sdk.Bech32MainPrefix,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
)

bankKeeper := bankkeeper.NewBaseKeeper(
appCodec,
nil,
accountKeeper,
BlockedAddresses(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
)

feeGrantKeeper := feegrantkeeper.NewKeeper(appCodec, nil, accountKeeper)
Expand All @@ -55,8 +55,8 @@ func newTestHandlerOptions() HandlerOptions {
nil,
nil,
[]string{
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
delaymsgmoduletypes.ModuleAddress.String(),
lib.GovModuleAddress.String(),
},
memClob,
nil,
Expand Down
60 changes: 30 additions & 30 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func New(

// set the BaseApp's parameter store
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(
appCodec, keys[upgradetypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())
appCodec, keys[upgradetypes.StoreKey], lib.GovModuleAddress.String())
bApp.SetParamStore(&app.ConsensusParamsKeeper)

// add capability keeper and ScopeToModule for ibc module
Expand All @@ -396,21 +396,21 @@ func New(
authtypes.ProtoBaseAccount,
maccPerms,
sdk.Bech32MainPrefix,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
keys[banktypes.StoreKey],
app.AccountKeeper,
BlockedAddresses(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
)
app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
)

app.DistrKeeper = distrkeeper.NewKeeper(
Expand All @@ -420,20 +420,20 @@ func New(
app.BankKeeper,
app.StakingKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
legacyAmino,
keys[slashingtypes.StoreKey],
app.StakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
)

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
app.CrisisKeeper = crisiskeeper.NewKeeper(appCodec, keys[crisistypes.StoreKey], invCheckPeriod,
app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())
app.BankKeeper, authtypes.FeeCollectorName, lib.GovModuleAddress.String())

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)

Expand All @@ -456,7 +456,7 @@ func New(
appCodec,
homePath,
app.BaseApp,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
)

// ... other modules keepers
Expand All @@ -476,7 +476,7 @@ func New(
*/
govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.AccountKeeper, app.BankKeeper,
app.StakingKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.StakingKeeper, app.MsgServiceRouter(), govConfig, lib.GovModuleAddress.String(),
)

app.GovKeeper = govKeeper.SetHooks(
Expand Down Expand Up @@ -673,8 +673,8 @@ func New(
app.IndexerEventManager,
// set the governance and delaymsg module accounts as the authority for conducting upgrades
[]string{
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
)
pricesModule := pricesmodule.NewAppModule(appCodec, app.PricesKeeper, app.AccountKeeper, app.BankKeeper)
Expand All @@ -692,8 +692,8 @@ func New(
keys[blocktimemoduletypes.StoreKey],
// set the governance and delaymsg module accounts as the authority for conducting upgrades
[]string{
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
)
blockTimeModule := blocktimemodule.NewAppModule(appCodec, app.BlockTimeKeeper)
Expand All @@ -704,7 +704,7 @@ func New(
bApp.MsgServiceRouter(),
// Permit delayed messages to be signed by the following modules.
[]string{
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
},
)
delayMsgModule := delaymsgmodule.NewAppModule(appCodec, app.DelayMsgKeeper)
Expand All @@ -717,8 +717,8 @@ func New(
app.DelayMsgKeeper,
// gov module and delayMsg module accounts are allowed to send messages to the bridge module.
[]string{
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
)
bridgeModule := bridgemodule.NewAppModule(appCodec, app.BridgeKeeper)
Expand All @@ -731,8 +731,8 @@ func New(
app.IndexerEventManager,
// gov module and delayMsg module accounts are allowed to send messages to the bridge module.
[]string{
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
)
perpetualsModule := perpetualsmodule.NewAppModule(appCodec, app.PerpetualsKeeper, app.AccountKeeper, app.BankKeeper)
Expand All @@ -744,8 +744,8 @@ func New(
tkeys[statsmoduletypes.TransientStoreKey],
// set the governance and delaymsg module accounts as the authority for conducting upgrades
[]string{
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
)
statsModule := statsmodule.NewAppModule(appCodec, app.StatsKeeper)
Expand All @@ -756,8 +756,8 @@ func New(
keys[feetiersmoduletypes.StoreKey],
// set the governance and delaymsg module accounts as the authority for conducting upgrades
[]string{
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
)
feeTiersModule := feetiersmodule.NewAppModule(appCodec, app.FeeTiersKeeper)
Expand All @@ -769,8 +769,8 @@ func New(
app.BlockTimeKeeper,
// set the governance and delaymsg module accounts as the authority for conducting upgrades
[]string{
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
)
vestModule := vestmodule.NewAppModule(appCodec, app.VestKeeper)
Expand All @@ -785,8 +785,8 @@ func New(
app.PricesKeeper,
// set the governance and delaymsg module accounts as the authority for conducting upgrades
[]string{
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
)
rewardsModule := rewardsmodule.NewAppModule(appCodec, app.RewardsKeeper)
Expand Down Expand Up @@ -816,8 +816,8 @@ func New(
tkeys[clobmoduletypes.TransientStoreKey],
// set the governance and delaymsg module accounts as the authority for conducting upgrades
[]string{
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
memClob,
app.SubaccountsKeeper,
Expand Down Expand Up @@ -853,8 +853,8 @@ func New(
app.IndexerEventManager,
// gov module and delayMsg module accounts are allowed to send messages to the sending module.
[]string{
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
authtypes.NewModuleAddress(delaymsgmoduletypes.ModuleName).String(),
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
)
sendingModule := sendingmodule.NewAppModule(
Expand Down
11 changes: 11 additions & 0 deletions protocol/lib/module_addresses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lib

import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

var (
// GovModuleAddress is the module address for the gov module.
GovModuleAddress = authtypes.NewModuleAddress(govtypes.ModuleName)
)
11 changes: 11 additions & 0 deletions protocol/lib/module_addresses_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lib_test

import (
"github.com/dydxprotocol/v4-chain/protocol/lib"
"github.com/stretchr/testify/require"
"testing"
)

func TestGovModuleAddress(t *testing.T) {
require.Equal(t, "dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky", lib.GovModuleAddress.String())
}
Loading

0 comments on commit 9b416b3

Please sign in to comment.