Skip to content

Commit

Permalink
Merge pull request #182 from terra-money/feat/feeshare
Browse files Browse the repository at this point in the history
feat: feeshare module
  • Loading branch information
tuky191 committed Oct 16, 2023
2 parents 64783d3 + f48f4b3 commit e5aaaf9
Show file tree
Hide file tree
Showing 69 changed files with 11,824 additions and 587 deletions.
6 changes: 6 additions & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
"github.com/skip-mev/pob/mempool"
pobante "github.com/skip-mev/pob/x/builder/ante"
pobkeeper "github.com/skip-mev/pob/x/builder/keeper"
feeshareante "github.com/terra-money/core/v2/x/feeshare/ante"
feesharekeeper "github.com/terra-money/core/v2/x/feeshare/keeper"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand All @@ -22,6 +25,8 @@ type HandlerOptions struct {
ante.HandlerOptions

IBCkeeper *ibckeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
BankKeeper bankKeeper.Keeper
TxCounterStoreKey storetypes.StoreKey
WasmConfig wasmTypes.WasmConfig
PobBuilderKeeper pobkeeper.Keeper
Expand Down Expand Up @@ -67,6 +72,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
feeshareante.NewFeeSharePayoutDecorator(options.BankKeeper, options.FeeShareKeeper),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
25 changes: 24 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ import (
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
terracustombank "github.com/terra-money/core/v2/custom/bank"
custombankkeeper "github.com/terra-money/core/v2/custom/bank/keeper"
feeshare "github.com/terra-money/core/v2/x/feeshare"
feesharekeeper "github.com/terra-money/core/v2/x/feeshare/keeper"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"

pobabci "github.com/skip-mev/pob/abci"
pobmempool "github.com/skip-mev/pob/mempool"
Expand Down Expand Up @@ -261,6 +264,7 @@ var (
wasm.AppModuleBasic{},
consensus.AppModuleBasic{},
alliance.AppModuleBasic{},
feeshare.AppModuleBasic{},
pob.AppModuleBasic{},
)

Expand Down Expand Up @@ -337,6 +341,7 @@ type TerraApp struct {
RouterKeeper routerkeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper
AllianceKeeper alliancekeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper

// IBC hooks
IBCHooksKeeper *ibchookskeeper.Keeper
Expand Down Expand Up @@ -410,7 +415,7 @@ func NewTerraApp(
icahosttypes.StoreKey, icacontrollertypes.StoreKey, routertypes.StoreKey,
consensusparamtypes.StoreKey, tokenfactorytypes.StoreKey, wasmtypes.StoreKey,
ibcfeetypes.StoreKey, ibchookstypes.StoreKey, crisistypes.StoreKey,
alliancetypes.StoreKey, pobtype.StoreKey,
alliancetypes.StoreKey, feesharetypes.StoreKey, pobtype.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -712,6 +717,16 @@ func NewTerraApp(
app.MsgServiceRouter(), govtypes.DefaultConfig(), authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.FeeShareKeeper = feesharekeeper.NewKeeper(
appCodec,
keys[feesharetypes.StoreKey],
app.BankKeeper,
app.WasmKeeper,
app.AccountKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Set legacy router for backwards compatibility with gov v1beta1
govKeeper.SetLegacyRouter(govRouter)
app.GovKeeper = *govKeeper.SetHooks(
Expand Down Expand Up @@ -769,6 +784,7 @@ func NewTerraApp(
ibchooks.NewAppModule(app.AccountKeeper),
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(tokenfactorytypes.ModuleName)),
alliance.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancetypes.ModuleName)),
feeshare.NewAppModule(app.FeeShareKeeper, app.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
pob.NewAppModule(appCodec, app.BuilderKeeper),
)

Expand Down Expand Up @@ -803,6 +819,7 @@ func NewTerraApp(
wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
alliancetypes.ModuleName,
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
pobtype.ModuleName,
)
Expand Down Expand Up @@ -834,6 +851,7 @@ func NewTerraApp(
wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
alliancetypes.ModuleName,
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
pobtype.ModuleName,
)
Expand Down Expand Up @@ -869,6 +887,7 @@ func NewTerraApp(
ibchookstypes.ModuleName,
wasmtypes.ModuleName,
alliancetypes.ModuleName,
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
pobtype.ModuleName,
)
Expand Down Expand Up @@ -897,6 +916,8 @@ func NewTerraApp(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: cosmosante.DefaultSigVerificationGasConsumer,
},
BankKeeper: app.BankKeeper,
FeeShareKeeper: app.FeeShareKeeper,
IBCkeeper: app.IBCKeeper,
TxCounterStoreKey: keys[wasmtypes.StoreKey],
WasmConfig: wasmConfig.ToWasmConfig(),
Expand Down Expand Up @@ -1206,6 +1227,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(tokenfactorytypes.ModuleName).WithKeyTable(tokenfactorytypes.ParamKeyTable())
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(alliancetypes.ModuleName).WithKeyTable(alliancetypes.ParamKeyTable())
paramsKeeper.Subspace(feesharetypes.ModuleName).WithKeyTable(feesharetypes.ParamKeyTable())

paramsKeeper.Subspace(wasmtypes.ModuleName).WithKeyTable(wasmtypes.ParamKeyTable())

Expand Down Expand Up @@ -1310,6 +1332,7 @@ func (app *TerraApp) SimulationManager() *module.SimulationManager {
router.NewAppModule(&app.RouterKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
alliance.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancetypes.ModuleName)),
feeshare.NewAppModule(app.FeeShareKeeper, app.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
)

sm.RegisterStoreDecoders()
Expand Down
3 changes: 3 additions & 0 deletions app/app_test/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/terra-money/alliance/x/alliance"
"github.com/terra-money/core/v2/app/wasmconfig"
"github.com/terra-money/core/v2/x/feeshare"
"github.com/terra-money/core/v2/x/tokenfactory"

tmtypes "github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -150,6 +151,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
"distribution": distribution.AppModule{}.ConsensusVersion(),
"evidence": evidence.AppModule{}.ConsensusVersion(),
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
"feeshare": feeshare.AppModule{}.ConsensusVersion(),
"feeibc": ibcfee.AppModule{}.ConsensusVersion(),
"genutil": genutil.AppModule{}.ConsensusVersion(),
"gov": gov.AppModule{}.ConsensusVersion(),
Expand Down Expand Up @@ -181,6 +183,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
"distribution": 3,
"evidence": 1,
"feegrant": 2,
"feeshare": 2,
"feeibc": 1,
"genutil": 1,
"gov": 4,
Expand Down
23 changes: 17 additions & 6 deletions app/app_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
"github.com/stretchr/testify/suite"
"github.com/terra-money/core/v2/app"
terra_app "github.com/terra-money/core/v2/app"
"github.com/terra-money/core/v2/app/config"
appparams "github.com/terra-money/core/v2/app/params"
terrraParams "github.com/terra-money/core/v2/app/params"
"github.com/terra-money/core/v2/app/wasmconfig"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"
)

Expand All @@ -44,8 +45,10 @@ type AppTestSuite struct {
// Setup sets up basic environment for suite (App, Ctx, and test accounts)
func (s *AppTestSuite) Setup() {
appparams.RegisterAddressesConfig()
baseTestAccts := CreateRandomAccounts(3)
encCfg := terra_app.MakeEncodingConfig()
genesisState := app.NewDefaultGenesisState(encCfg.Marshaler)
genesisState.ConfigureBondDenom(encCfg.Marshaler, config.BondDenom)
genesisState.ConfigureICA(encCfg.Marshaler)

db := dbm.NewMemDB()
s.App = terra_app.NewTerraApp(
Expand All @@ -61,21 +64,26 @@ func (s *AppTestSuite) Setup() {
wasmconfig.DefaultConfig(),
)

s.TestAccs = []sdk.AccAddress{}
s.TestAccs = append(s.TestAccs, baseTestAccts...)
s.Ctx = s.App.NewContext(true, tmproto.Header{Height: 1, Time: time.Now()})
s.QueryHelper = &baseapp.QueryServiceTestHelper{
GRPCQueryRouter: s.App.GRPCQueryRouter(),
Ctx: s.Ctx,
}
err := s.App.BankKeeper.SetParams(s.Ctx, banktypes.NewParams(true))
s.Require().NoError(err)

err = s.App.WasmKeeper.SetParams(s.Ctx, wasmtypes.DefaultParams())
s.Require().NoError(err)

err = s.App.FeeShareKeeper.SetParams(s.Ctx, feesharetypes.DefaultParams())
s.Require().NoError(err)

err = s.App.TokenFactoryKeeper.SetParams(s.Ctx, tokenfactorytypes.DefaultParams())
s.Require().NoError(err)

s.App.DistrKeeper.SetFeePool(s.Ctx, distrtypes.InitialFeePool())

s.TestAccs = s.CreateRandomAccounts(3)
}

func (s *AppTestSuite) AssertEventEmitted(ctx sdk.Context, eventTypeExpected string, numEventsExpected int) {
Expand All @@ -91,11 +99,14 @@ func (s *AppTestSuite) AssertEventEmitted(ctx sdk.Context, eventTypeExpected str
}

// CreateRandomAccounts is a function return a list of randomly generated AccAddresses
func CreateRandomAccounts(numAccts int) []sdk.AccAddress {
func (s *AppTestSuite) CreateRandomAccounts(numAccts int) []sdk.AccAddress {
testAddrs := make([]sdk.AccAddress, numAccts)
for i := 0; i < numAccts; i++ {
pk := ed25519.GenPrivKey().PubKey()
testAddrs[i] = sdk.AccAddress(pk.Address())

err := s.FundAcc(testAddrs[i], sdk.NewCoins(sdk.NewInt64Coin("uluna", 100000000)))
s.Require().NoError(err)
}

return testAddrs
Expand All @@ -116,7 +127,7 @@ func SetupGenesisValSet(
genAccs []authtypes.GenesisAccount,
opts []wasm.Option,
app *terra_app.TerraApp,
encCfg terrraParams.EncodingConfig,
encCfg appparams.EncodingConfig,
balances ...banktypes.Balance,
) terra_app.GenesisState {
genesisState := terra_app.NewDefaultGenesisState(encCfg.Marshaler)
Expand Down
Loading

0 comments on commit e5aaaf9

Please sign in to comment.