diff --git a/ante/ante.go b/ante/ante.go index b82f0604bcc..f6861d5d6de 100644 --- a/ante/ante.go +++ b/ante/ante.go @@ -14,6 +14,9 @@ import ( gaiaerrors "github.com/cosmos/gaia/v15/types/errors" gaiafeeante "github.com/cosmos/gaia/v15/x/globalfee/ante" + + feeabsante "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/ante" + feeabskeeper "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/keeper" ) // HandlerOptions extend the SDK's AnteHandler options by requiring the IBC @@ -25,6 +28,7 @@ type HandlerOptions struct { GlobalFeeSubspace paramtypes.Subspace StakingKeeper *stakingkeeper.Keeper TxFeeChecker ante.TxFeeChecker + FeeAbskeeper feeabskeeper.Keeper } func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { @@ -57,13 +61,15 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { anteDecorators := []sdk.AnteDecorator{ ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker), + feeabsante.NewFeeAbstrationMempoolFeeDecorator(opts.FeeAbskeeper), ante.NewValidateBasicDecorator(), ante.NewTxTimeoutHeightDecorator(), ante.NewValidateMemoDecorator(opts.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper), NewGovVoteDecorator(opts.Codec, opts.StakingKeeper), gaiafeeante.NewFeeDecorator(opts.GlobalFeeSubspace, opts.StakingKeeper), - ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker), + // ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker), + feeabsante.NewFeeAbstractionDeductFeeDecorate(opts.AccountKeeper, opts.BankKeeper, opts.FeeAbskeeper, opts.FeegrantKeeper), ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewValidateSigCountDecorator(opts.AccountKeeper), ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer), diff --git a/app/app.go b/app/app.go index 9165aaeb977..6bed2595595 100644 --- a/app/app.go +++ b/app/app.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "path/filepath" + "sort" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" @@ -51,6 +52,8 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + // feeabstypes "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/types" + gaiaante "github.com/cosmos/gaia/v15/ante" "github.com/cosmos/gaia/v15/app/keepers" "github.com/cosmos/gaia/v15/app/params" @@ -230,6 +233,7 @@ func NewGaiaApp( // If TxFeeChecker is nil the default ante TxFeeChecker is used // so we use this no-op to keep the global fee module behaviour unchanged TxFeeChecker: noOpTxFeeChecker, + FeeAbskeeper: app.FeeabsKeeper, }, ) if err != nil { @@ -285,12 +289,19 @@ func (app *GaiaApp) LoadHeight(height int64) error { // ModuleAccountAddrs returns all the app's module account addresses. func (app *GaiaApp) ModuleAccountAddrs() map[string]bool { - modAccAddrs := make(map[string]bool) - for acc := range maccPerms { - modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true + blockedAddrs := make(map[string]bool) + + accs := make([]string, 0, len(maccPerms)) + for k := range maccPerms { + accs = append(accs, k) } + sort.Strings(accs) - return modAccAddrs + for _, acc := range accs { + blockedAddrs[authtypes.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc] + } + + return blockedAddrs } // BlockedModuleAccountAddrs returns all the app's blocked module account diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 30adea4f69d..5e1e0352ba1 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -69,6 +69,10 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/cosmos/gaia/v15/x/globalfee" + + feeabsmodule "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs" + feeabskeeper "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/keeper" + feeabstypes "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/types" ) type AppKeepers struct { @@ -114,6 +118,9 @@ type AppKeepers struct { ScopedTransferKeeper capabilitykeeper.ScopedKeeper ScopedICAHostKeeper capabilitykeeper.ScopedKeeper ScopedIBCProviderKeeper capabilitykeeper.ScopedKeeper + ScopedFeeabsKeeper capabilitykeeper.ScopedKeeper + + FeeabsKeeper feeabskeeper.Keeper } func NewAppKeeper( @@ -171,6 +178,7 @@ func NewAppKeeper( appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) appKeepers.ScopedIBCProviderKeeper = appKeepers.CapabilityKeeper.ScopeToModule(providertypes.ModuleName) + appKeepers.ScopedFeeabsKeeper = appKeepers.CapabilityKeeper.ScopeToModule(feeabstypes.ModuleName) // Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating // their scoped modules in `NewApp` with `ScopeToModule` @@ -315,6 +323,21 @@ func NewAppKeeper( appKeepers.ProviderModule = ibcprovider.NewAppModule(&appKeepers.ProviderKeeper, appKeepers.GetSubspace(providertypes.ModuleName)) + appKeepers.FeeabsKeeper = feeabskeeper.NewKeeper( + appCodec, + appKeepers.keys[feeabstypes.StoreKey], + appKeepers.GetSubspace(feeabstypes.ModuleName), + appKeepers.StakingKeeper, + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.TransferKeeper, + appKeepers.IBCKeeper.ChannelKeeper, + &appKeepers.IBCKeeper.PortKeeper, + appKeepers.ScopedFeeabsKeeper, + ) + + feeabsIBCModule := feeabsmodule.NewIBCModule(appCodec, appKeepers.FeeabsKeeper) + // Register the proposal types // Deprecated: Avoid adding new handlers, instead use the new proposal flow // by granting the governance module the right to execute the message. @@ -325,7 +348,8 @@ func NewAppKeeper( AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)). AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)). - AddRoute(providertypes.RouterKey, ibcprovider.NewProviderProposalHandler(appKeepers.ProviderKeeper)) + AddRoute(providertypes.RouterKey, ibcprovider.NewProviderProposalHandler(appKeepers.ProviderKeeper)). + AddRoute(feeabstypes.RouterKey, feeabsmodule.NewHostZoneProposal(appKeepers.FeeabsKeeper)) // Set legacy router for backwards compatibility with gov v1beta1 appKeepers.GovKeeper.SetLegacyRouter(govRouter) @@ -410,7 +434,8 @@ func NewAppKeeper( ibcRouter := porttypes.NewRouter(). AddRoute(icahosttypes.SubModuleName, icaHostStack). AddRoute(ibctransfertypes.ModuleName, transferStack). - AddRoute(providertypes.ModuleName, appKeepers.ProviderModule) + AddRoute(providertypes.ModuleName, appKeepers.ProviderModule). + AddRoute(feeabstypes.ModuleName, feeabsIBCModule) appKeepers.IBCKeeper.SetRouter(ibcRouter) @@ -445,6 +470,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(pfmroutertypes.ModuleName).WithKeyTable(pfmroutertypes.ParamKeyTable()) paramsKeeper.Subspace(globalfee.ModuleName) paramsKeeper.Subspace(providertypes.ModuleName) + paramsKeeper.Subspace(feeabstypes.ModuleName).WithKeyTable(feeabstypes.ParamKeyTable()) return paramsKeeper } diff --git a/app/keepers/keys.go b/app/keepers/keys.go index 5996f2437c4..a548b79cd1a 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -24,6 +24,8 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + feeabstypes "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/types" ) func (appKeepers *AppKeepers) GenerateKeys() { @@ -43,6 +45,7 @@ func (appKeepers *AppKeepers) GenerateKeys() { upgradetypes.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, + feeabstypes.StoreKey, icahosttypes.StoreKey, capabilitytypes.StoreKey, feegrant.StoreKey, diff --git a/app/modules.go b/app/modules.go index 661e4eae6a2..a58b9bad08a 100644 --- a/app/modules.go +++ b/app/modules.go @@ -57,6 +57,9 @@ import ( gaiaappparams "github.com/cosmos/gaia/v15/app/params" "github.com/cosmos/gaia/v15/x/globalfee" + + feeabsmodule "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs" + feeabstypes "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/types" ) var maccPerms = map[string][]string{ @@ -70,6 +73,12 @@ var maccPerms = map[string][]string{ // liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, providertypes.ConsumerRewardsPool: nil, + feeabstypes.ModuleName: nil, +} + +// module accounts that are allowed to receive tokens +var allowedReceivingModAcc = map[string]bool{ + feeabstypes.ModuleName: true, } // ModuleBasics defines the module BasicManager is in charge of setting up basic, @@ -93,6 +102,9 @@ var ModuleBasics = module.NewBasicManager( icsproviderclient.ConsumerAdditionProposalHandler, icsproviderclient.ConsumerRemovalProposalHandler, icsproviderclient.ChangeRewardDenomsProposalHandler, + feeabsmodule.UpdateAddHostZoneClientProposalHandler, + feeabsmodule.UpdateDeleteHostZoneClientProposalHandler, + feeabsmodule.UpdateSetHostZoneClientProposalHandler, }, ), sdkparams.AppModuleBasic{}, @@ -111,6 +123,7 @@ var ModuleBasics = module.NewBasicManager( globalfee.AppModule{}, icsprovider.AppModuleBasic{}, consensus.AppModuleBasic{}, + feeabsmodule.AppModuleBasic{}, ) func appModules( @@ -149,6 +162,7 @@ func appModules( app.ICAModule, app.PFMRouterModule, app.ProviderModule, + feeabsmodule.NewAppModule(appCodec, app.FeeabsKeeper), } } @@ -209,6 +223,7 @@ func orderBeginBlockers() []string { crisistypes.ModuleName, ibcexported.ModuleName, ibctransfertypes.ModuleName, + feeabstypes.ModuleName, icatypes.ModuleName, pfmroutertypes.ModuleName, genutiltypes.ModuleName, @@ -237,6 +252,7 @@ func orderEndBlockers() []string { stakingtypes.ModuleName, ibcexported.ModuleName, ibctransfertypes.ModuleName, + feeabstypes.ModuleName, icatypes.ModuleName, pfmroutertypes.ModuleName, capabilitytypes.ModuleName, @@ -280,6 +296,7 @@ func orderInitBlockers() []string { genutiltypes.ModuleName, ibctransfertypes.ModuleName, ibcexported.ModuleName, + feeabstypes.ModuleName, icatypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, diff --git a/go.mod b/go.mod index 3ab289a3a87..f46ca6f3e45 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/google/gofuzz v1.2.0 github.com/gorilla/mux v1.8.1 github.com/ory/dockertest/v3 v3.10.0 + github.com/osmosis-labs/fee-abstraction/v7 v7.0.0-20240302165344-d32627920fad github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.6.0 github.com/spf13/cobra v1.8.0 diff --git a/go.sum b/go.sum index 458420b88b1..0b409e4f898 100644 --- a/go.sum +++ b/go.sum @@ -1229,6 +1229,8 @@ github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4 github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs= github.com/ory/dockertest/v3 v3.10.0 h1:4K3z2VMe8Woe++invjaTB7VRyQXQy5UY+loujO4aNE4= github.com/ory/dockertest/v3 v3.10.0/go.mod h1:nr57ZbRWMqfsdGdFNLHz5jjNdDb7VVFnzAeW1n5N1Lg= +github.com/osmosis-labs/fee-abstraction/v7 v7.0.0-20240302165344-d32627920fad h1:Kec3RfBVG34oSXp5yNNrwrXTp5oKVAxRE9P8yVHWZMc= +github.com/osmosis-labs/fee-abstraction/v7 v7.0.0-20240302165344-d32627920fad/go.mod h1:y/N5kGya7AQm/kfBvlhi2CmwjsXMXGHOuRQ1WH7jK8Y= github.com/oxyno-zeta/gomock-extra-matcher v1.2.0 h1:WPEclU0y0PMwUzdDcaKZvld4aXpa3fkzjiUMQdcBEHg= github.com/oxyno-zeta/gomock-extra-matcher v1.2.0/go.mod h1:S0r7HmKeCGsHmvIVFMjKWwswb4+30nCNWbXRMBVPkaU= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= diff --git a/startnode.sh b/startnode.sh new file mode 100644 index 00000000000..827ec646128 --- /dev/null +++ b/startnode.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +set -eux + +rm -rf $HOME/.gaia + +BINARY=gaiad +MONIKER=localgaia +CHAIN_ID=gaia-feeabs-1 +KEYRING="test" +DENOM=uatom + +$BINARY config chain-id $CHAIN_ID +$BINARY config keyring-backend $KEYRING + +command -v gaiad >/dev/null 2>&1 || { + echo >&2 "gaiad command not found. Ensure this is setup / properly installed in your GOPATH." + exit 1 +} +command -v jq >/dev/null 2>&1 || { + echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/" + exit 1 +} + +yes | $BINARY keys add validator +yes | $BINARY keys add creator +yes | $BINARY keys add investor +yes | $BINARY keys add relayer + +VALIDATOR=$($BINARY keys show validator -a) +CREATOR=$($BINARY keys show creator -a) +INVESTOR=$($BINARY keys show investor -a) +RELAYER=$($BINARY keys show relayer -a) + +# setup chain +$BINARY init $MONIKER --chain-id $CHAIN_ID +gsed -i "s/\"stake\"/\"$DENOM\"/g" ~/.gaia/config/genesis.json +# modify config for development +config="$HOME/.gaia/config/config.toml" +gsed -i "s/cors_allowed_origins = \[\]/cors_allowed_origins = [\"*\"]/g" $config +gsed -i "s/\"stake\"/\"$DENOM\"/g" ~/.gaia/config/genesis.json +# modify genesis params for localnet ease of use +# x/gov params change +# reduce voting period to 1 minutes +contents="$(jq '.app_state.gov.params.voting_period = "60s"' $HOME/.gaia/config/genesis.json)" && echo "${contents}" >$HOME/.gaia/config/genesis.json +# reduce minimum deposit amount to 10stake +contents="$(jq '.app_state.gov.params.min_deposit[0].amount = "10"' $HOME/.gaia/config/genesis.json)" && echo "${contents}" >$HOME/.gaia/config/genesis.json +# reduce deposit period to 20seconds +contents="$(jq '.app_state.gov.params.max_deposit_period = "20s"' $HOME/.gaia/config/genesis.json)" && echo "${contents}" >$HOME/.gaia/config/genesis.json + +$BINARY genesis add-genesis-account $VALIDATOR "10000000000000000$DENOM" +$BINARY genesis add-genesis-account $CREATOR "10000000000000000$DENOM" +$BINARY genesis add-genesis-account $INVESTOR "10000000000000000$DENOM" +$BINARY genesis add-genesis-account $RELAYER "10000000000000000$DENOM" + +$BINARY genesis gentx validator 10000000000uatom --chain-id $CHAIN_ID --keyring-backend $KEYRING +$BINARY genesis collect-gentxs +$BINARY genesis validate-genesis + +$BINARY start --minimum-gas-prices 0.00uatom