Skip to content

Commit

Permalink
Merge pull request #206 from terra-money/refact/v2.7/feeshare
Browse files Browse the repository at this point in the history
refact(v2.7): feeshare
  • Loading branch information
emidev98 authored Nov 21, 2023
2 parents a49f09f + 3ed296d commit ec11083
Show file tree
Hide file tree
Showing 57 changed files with 2,648 additions and 513 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/codecommit.yml

This file was deleted.

24 changes: 16 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ update-swagger-docs: statik

proto-all: proto-gen proto-swagger update-swagger-docs

.PHONY: proto-gen gen-swagger update-swagger-docs apply-swagger proto-all
.PHONY: proto-gen gen-swagger update-swagger-docs proto-all

########################################
### Tools & dependencies
Expand Down Expand Up @@ -328,11 +328,19 @@ lint:

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0

.PHONY: lint lint-fix

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -path "./_build/*" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -path "./_build/*" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -path "./_build/*" | xargs goimports -w -local github.com/cosmos/cosmos-sdk
.PHONY: format
lint-docker:
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:latest golangci-lint run --timeout 10m

format-tools:
go install mvdan.cc/gofumpt@latest
go install github.com/client9/misspell/cmd/misspell@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

format: format-tools
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*statik*" -not -name '*.pb.go' | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*statik*" -not -name '*.pb.go' | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*statik*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk

.PHONY: lint lint-fix lint-docker format-tools format
2 changes: 0 additions & 2 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"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"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -73,7 +72,6 @@ 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
21 changes: 16 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"path/filepath"
"reflect" // #nosec G702

authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
"github.com/prometheus/client_golang/prometheus"

authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/terra-money/core/v2/app/keepers"
"github.com/terra-money/core/v2/app/post"
"github.com/terra-money/core/v2/app/rpc"
tokenfactorybindings "github.com/terra-money/core/v2/x/tokenfactory/bindings"

Expand All @@ -27,6 +29,9 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec/types"

custombankmodule "github.com/terra-money/core/v2/x/bank"
customwasmodule "github.com/terra-money/core/v2/x/wasm"

"github.com/cosmos/cosmos-sdk/baseapp"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand All @@ -44,7 +49,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
"github.com/cosmos/cosmos-sdk/x/crisis"
Expand Down Expand Up @@ -77,7 +81,6 @@ import (
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

"github.com/terra-money/alliance/x/alliance"
Expand Down Expand Up @@ -279,6 +282,13 @@ func NewTerraApp(
if err != nil {
panic(err)
}
postHandler := post.NewPostHandler(
post.HandlerOptions{
FeeShareKeeper: app.Keepers.FeeShareKeeper,
BankKeeper: app.Keepers.BankKeeper,
WasmKeeper: app.Keepers.WasmKeeper,
},
)

// Create the proposal handler that will be used to build and validate blocks.
handler := pobabci.NewProposalHandler(
Expand All @@ -304,6 +314,7 @@ func NewTerraApp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(anteHandler)
app.SetPostHandler(postHandler)
app.SetEndBlocker(app.EndBlocker)
app.SetMempool(pobMempool)
app.SetCheckTx(checkTxHandler.CheckTx())
Expand Down Expand Up @@ -541,7 +552,7 @@ func (app *TerraApp) SimulationManager() *module.SimulationManager {
sm := module.NewSimulationManager(
auth.NewAppModule(appCodec, app.Keepers.AccountKeeper, authsims.RandomGenesisAccounts, app.Keepers.GetSubspace(authtypes.ModuleName)),
authzmodule.NewAppModule(appCodec, app.Keepers.AuthzKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.interfaceRegistry),
bank.NewAppModule(appCodec, app.Keepers.BankKeeper, app.Keepers.AccountKeeper, app.Keepers.GetSubspace(banktypes.ModuleName)),
custombankmodule.NewAppModule(appCodec, app.Keepers.BankKeeper, app.Keepers.AccountKeeper, app.Keepers.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.Keepers.CapabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.Keepers.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.Keepers.GovKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.Keepers.GetSubspace(govtypes.ModuleName)),
Expand All @@ -556,7 +567,7 @@ func (app *TerraApp) SimulationManager() *module.SimulationManager {
ibcfee.NewAppModule(app.Keepers.IBCFeeKeeper),
ica.NewAppModule(&app.Keepers.ICAControllerKeeper, &app.Keepers.ICAHostKeeper),
router.NewAppModule(&app.Keepers.RouterKeeper),
wasm.NewAppModule(appCodec, &app.Keepers.WasmKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.BaseApp.MsgServiceRouter(), app.Keepers.GetSubspace(wasmtypes.ModuleName)),
customwasmodule.NewAppModule(appCodec, &app.Keepers.WasmKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.BaseApp.MsgServiceRouter(), app.Keepers.GetSubspace(wasmtypes.ModuleName)),
alliance.NewAppModule(appCodec, app.Keepers.AllianceKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.interfaceRegistry, app.Keepers.GetSubspace(alliancetypes.ModuleName)),
feeshare.NewAppModule(app.Keepers.FeeShareKeeper, app.Keepers.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
)
Expand Down
23 changes: 19 additions & 4 deletions app/app_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ import (
type AppTestSuite struct {
suite.Suite

App *app.TerraApp
Ctx sdk.Context
QueryHelper *baseapp.QueryServiceTestHelper
TestAccs []sdk.AccAddress
App *app.TerraApp
Ctx sdk.Context
QueryHelper *baseapp.QueryServiceTestHelper
TestAccs []sdk.AccAddress
EncodingConfig appparams.EncodingConfig
}

// Setup sets up basic environment for suite (App, Ctx, and test accounts)
Expand All @@ -62,6 +63,7 @@ func (s *AppTestSuite) Setup() {
simtestutil.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
)
s.EncodingConfig = encCfg

s.Ctx = s.App.NewContext(true, tmproto.Header{Height: 1, Time: time.Now()})
s.QueryHelper = &baseapp.QueryServiceTestHelper{
Expand All @@ -80,6 +82,9 @@ func (s *AppTestSuite) Setup() {
err = s.App.Keepers.TokenFactoryKeeper.SetParams(s.Ctx, tokenfactorytypes.DefaultParams())
s.Require().NoError(err)

err = s.FundModule(authtypes.FeeCollectorName, sdk.NewCoins(sdk.NewCoin("uluna", sdk.NewInt(1000)), sdk.NewCoin("utoken", sdk.NewInt(500))))
s.Require().NoError(err)

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

s.TestAccs = s.CreateRandomAccounts(3)
Expand Down Expand Up @@ -121,6 +126,16 @@ func (s *AppTestSuite) FundAcc(acc sdk.AccAddress, amounts sdk.Coins) (err error
return s.App.Keepers.BankKeeper.SendCoinsFromModuleToAccount(s.Ctx, minttypes.ModuleName, acc, amounts)
}

// FundAcc funds target address with specified amount.
func (s *AppTestSuite) FundModule(moduleAccount string, amounts sdk.Coins) (err error) {
s.Require().NoError(err)
if err := s.App.Keepers.BankKeeper.MintCoins(s.Ctx, minttypes.ModuleName, amounts); err != nil {
return err
}

return s.App.Keepers.BankKeeper.SendCoinsFromModuleToModule(s.Ctx, minttypes.ModuleName, moduleAccount, amounts)
}

func SetupGenesisValSet(
valSet *tmtypes.ValidatorSet,
genAccs []authtypes.GenesisAccount,
Expand Down
23 changes: 13 additions & 10 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (

"path/filepath"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router"
ibctransfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/spf13/cast"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -28,11 +34,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/params"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/cosmos/cosmos-sdk/x/upgrade"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router"
ibctransfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/spf13/cast"

"github.com/cosmos/cosmos-sdk/x/feegrant"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
Expand All @@ -58,7 +59,6 @@ import (
routerkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/keeper"
routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types"

evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
icq "github.com/cosmos/ibc-apps/modules/async-icq/v7"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
Expand All @@ -71,6 +71,8 @@ import (
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"

evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"

icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v7/keeper"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types"

Expand All @@ -85,6 +87,7 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host"
customwasmkeeper "github.com/terra-money/core/v2/x/wasm/keeper"

icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
Expand All @@ -95,7 +98,7 @@ import (
"github.com/terra-money/alliance/x/alliance"
alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper"
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
custombankkeeper "github.com/terra-money/core/v2/custom/bank/keeper"
custombankkeeper "github.com/terra-money/core/v2/x/bank/keeper"
feesharekeeper "github.com/terra-money/core/v2/x/feeshare/keeper"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"

Expand Down Expand Up @@ -173,7 +176,7 @@ type TerraAppKeepers struct {
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICQKeeper capabilitykeeper.ScopedKeeper

WasmKeeper wasmkeeper.Keeper
WasmKeeper customwasmkeeper.Keeper
scopedWasmKeeper capabilitykeeper.ScopedKeeper

// BuilderKeeper is the keeper that handles processing auction transactions
Expand Down Expand Up @@ -453,7 +456,7 @@ func NewTerraAppKeepers(
panic("error while reading wasm config: " + err.Error())
}
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,token_factory"
keepers.WasmKeeper = wasmkeeper.NewKeeper(
keepers.WasmKeeper = customwasmkeeper.NewKeeper(
appCodec,
keys[wasmtypes.StoreKey],
keepers.AccountKeeper,
Expand All @@ -474,7 +477,7 @@ func NewTerraAppKeepers(
wasmOpts...,
)

keepers.Ics20WasmHooks.ContractKeeper = &keepers.WasmKeeper
keepers.Ics20WasmHooks.ContractKeeper = keepers.WasmKeeper.Keeper
// Setup the contract keepers.WasmKeeper before the
// hook for the BankKeeper othrwise the WasmKeeper
// will be nil inside the hooks.
Expand Down
23 changes: 13 additions & 10 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router"
routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types"
Expand All @@ -60,6 +54,13 @@ import (
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

icq "github.com/cosmos/ibc-apps/modules/async-icq/v7"

solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
Expand All @@ -68,19 +69,21 @@ import (
ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7"

"github.com/CosmWasm/wasmd/x/wasm"
custombankmodule "github.com/terra-money/core/v2/x/bank"
customwasmodule "github.com/terra-money/core/v2/x/wasm"

"github.com/terra-money/core/v2/x/tokenfactory"

"github.com/terra-money/alliance/x/alliance"
terracustombank "github.com/terra-money/core/v2/custom/bank"
feeshare "github.com/terra-money/core/v2/x/feeshare"

pob "github.com/skip-mev/pob/x/builder"
pobtype "github.com/skip-mev/pob/x/builder/types"

"github.com/cosmos/cosmos-sdk/x/feegrant"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
terrappsparams "github.com/terra-money/core/v2/app/params"

"github.com/cosmos/cosmos-sdk/x/feegrant"
)

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
Expand Down Expand Up @@ -130,7 +133,7 @@ func appModules(app *TerraApp, encodingConfig terrappsparams.EncodingConfig, ski
),
auth.NewAppModule(app.appCodec, app.Keepers.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)),
vesting.NewAppModule(app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.Keepers.DistrKeeper, app.Keepers.StakingKeeper),
terracustombank.NewAppModule(app.appCodec, app.Keepers.BankKeeper, app.Keepers.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
custombankmodule.NewAppModule(app.appCodec, app.Keepers.BankKeeper, app.Keepers.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(app.appCodec, *app.Keepers.CapabilityKeeper, false),
crisis.NewAppModule(&app.Keepers.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
feegrantmodule.NewAppModule(app.appCodec, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.Keepers.FeeGrantKeeper, app.interfaceRegistry),
Expand All @@ -149,7 +152,7 @@ func appModules(app *TerraApp, encodingConfig terrappsparams.EncodingConfig, ski
ibcfee.NewAppModule(app.Keepers.IBCFeeKeeper),
ica.NewAppModule(&app.Keepers.ICAControllerKeeper, &app.Keepers.ICAHostKeeper),
router.NewAppModule(&app.Keepers.RouterKeeper),
wasm.NewAppModule(app.appCodec, &app.Keepers.WasmKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
customwasmodule.NewAppModule(app.appCodec, &app.Keepers.WasmKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ibchooks.NewAppModule(app.Keepers.AccountKeeper),
tokenfactory.NewAppModule(app.Keepers.TokenFactoryKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.GetSubspace(tokenfactorytypes.ModuleName)),
alliance.NewAppModule(app.appCodec, app.Keepers.AllianceKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancetypes.ModuleName)),
Expand Down
Loading

0 comments on commit ec11083

Please sign in to comment.