Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fee Abstraction module #136

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down
19 changes: 15 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"path/filepath"
"sort"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -114,6 +118,9 @@ type AppKeepers struct {
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedIBCProviderKeeper capabilitykeeper.ScopedKeeper
ScopedFeeabsKeeper capabilitykeeper.ScopedKeeper

FeeabsKeeper feeabskeeper.Keeper
}

func NewAppKeeper(
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -43,6 +45,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
upgradetypes.StoreKey,
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
feeabstypes.StoreKey,
icahosttypes.StoreKey,
capabilitytypes.StoreKey,
feegrant.StoreKey,
Expand Down
17 changes: 17 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand All @@ -93,6 +102,9 @@ var ModuleBasics = module.NewBasicManager(
icsproviderclient.ConsumerAdditionProposalHandler,
icsproviderclient.ConsumerRemovalProposalHandler,
icsproviderclient.ChangeRewardDenomsProposalHandler,
feeabsmodule.UpdateAddHostZoneClientProposalHandler,
feeabsmodule.UpdateDeleteHostZoneClientProposalHandler,
feeabsmodule.UpdateSetHostZoneClientProposalHandler,
},
),
sdkparams.AppModuleBasic{},
Expand All @@ -111,6 +123,7 @@ var ModuleBasics = module.NewBasicManager(
globalfee.AppModule{},
icsprovider.AppModuleBasic{},
consensus.AppModuleBasic{},
feeabsmodule.AppModuleBasic{},
)

func appModules(
Expand Down Expand Up @@ -149,6 +162,7 @@ func appModules(
app.ICAModule,
app.PFMRouterModule,
app.ProviderModule,
feeabsmodule.NewAppModule(appCodec, app.FeeabsKeeper),
}
}

Expand Down Expand Up @@ -209,6 +223,7 @@ func orderBeginBlockers() []string {
crisistypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
feeabstypes.ModuleName,
icatypes.ModuleName,
pfmroutertypes.ModuleName,
genutiltypes.ModuleName,
Expand Down Expand Up @@ -237,6 +252,7 @@ func orderEndBlockers() []string {
stakingtypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
feeabstypes.ModuleName,
icatypes.ModuleName,
pfmroutertypes.ModuleName,
capabilitytypes.ModuleName,
Expand Down Expand Up @@ -280,6 +296,7 @@ func orderInitBlockers() []string {
genutiltypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
feeabstypes.ModuleName,
icatypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
60 changes: 60 additions & 0 deletions startnode.sh
Original file line number Diff line number Diff line change
@@ -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