Skip to content

Commit

Permalink
Merge pull request #367 from notional-labs/feeabs
Browse files Browse the repository at this point in the history
Add feeabs module
  • Loading branch information
hoank101 authored Apr 16, 2024
2 parents cb4e56d + 1203d1c commit 41e2e6a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"

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 @@ -26,6 +29,7 @@ type HandlerOptions struct {
BankKeeper bankkeeper.Keeper
WasmConfig *wasmTypes.WasmConfig
TXCounterStoreKey storetypes.StoreKey
FeeabsKeeper feeabskeeper.Keeper
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand Down Expand Up @@ -59,10 +63,12 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
feeabsante.NewFeeAbstrationMempoolFeeDecorator(options.FeeabsKeeper),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
feeabsante.NewFeeAbstractionDeductFeeDecorate(options.AccountKeeper, options.BankKeeper, options.FeeabsKeeper, options.FeegrantKeeper),
feeburnAnte.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker, *options.FeeburnKeeper),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
Expand Down
41 changes: 39 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ import (
feeburnmodulekeeper "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/x/feeburn/keeper"
feeburnmoduletypes "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/x/feeburn/types"

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"

// Note: please do your research before using this in production app, this is a demo and not an officially
// supported IBC team implementation. It has no known issues, but do your own research before using it.

Expand Down Expand Up @@ -224,6 +228,7 @@ var (
ica.AppModuleBasic{},
ibcfee.AppModuleBasic{},
feeburnmodule.AppModuleBasic{},
feeabsmodule.AppModuleBasic{},
)

// module account permissions
Expand All @@ -242,6 +247,7 @@ var (
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.RewardsPoolName: nil,
feeabstypes.ModuleName: nil,
}
)

Expand Down Expand Up @@ -296,6 +302,8 @@ type MigalooApp struct {
ConsensusParamsKeeper consensusparamkeeper.Keeper
FeeBurnKeeper feeburnmodulekeeper.Keeper

FeeabsKeeper feeabskeeper.Keeper

// IBC hooks
IBCHooksKeeper *ibchookskeeper.Keeper
TransferStack *ibcporttypes.IBCModule
Expand All @@ -307,6 +315,7 @@ type MigalooApp struct {
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedIBCFeeKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
ScopedFeeabsKeeper capabilitykeeper.ScopedKeeper

// Middleware wrapper
Ics20WasmHooks *ibchooks.WasmHooks
Expand Down Expand Up @@ -364,6 +373,7 @@ func NewMigalooApp(
alliancemoduletypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey,
ibchookstypes.StoreKey,
feeburnmoduletypes.StoreKey,
feeabstypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -404,6 +414,7 @@ func NewMigalooApp(
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)
scopedFeeabsKeeper := app.CapabilityKeeper.ScopeToModule(feeabstypes.ModuleName)

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -530,6 +541,19 @@ func NewMigalooApp(
authtypes.NewModuleAddress(govtypes.ModuleName),
)

app.FeeabsKeeper = feeabskeeper.NewKeeper(
appCodec,
app.keys[feeabstypes.StoreKey],
app.GetSubspace(feeabstypes.ModuleName),
app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
app.TransferKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
scopedFeeabsKeeper,
)

// 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 @@ -540,7 +564,8 @@ func NewMigalooApp(
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(&app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(alliancemoduletypes.RouterKey, alliancemodule.NewAllianceProposalHandler(app.AllianceKeeper)).
AddRoute(feeburnmoduletypes.RouterKey, feeburnmodule.NewFeeBurnProposalHandler(app.FeeBurnKeeper))
AddRoute(feeburnmoduletypes.RouterKey, feeburnmodule.NewFeeBurnProposalHandler(app.FeeBurnKeeper)).
AddRoute(feeabstypes.RouterKey, feeabsmodule.NewHostZoneProposal(app.FeeabsKeeper))

// Configure the hooks keeper
hooksKeeper := ibchookskeeper.NewKeeper(
Expand Down Expand Up @@ -714,7 +739,8 @@ func NewMigalooApp(
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ibctransfertypes.ModuleName, *app.TransferStack).
AddRoute(wasmtypes.ModuleName, wasmStack).
AddRoute(icqtypes.ModuleName, icqStack)
AddRoute(icqtypes.ModuleName, icqStack).
AddRoute(feeabstypes.ModuleName, feeabsmodule.NewIBCModule(appCodec, app.FeeabsKeeper))

app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -780,6 +806,7 @@ func NewMigalooApp(
icq.NewAppModule(app.ICQKeeper, app.GetSubspace(icqtypes.ModuleName)),
alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancemoduletypes.ModuleName)),
ibcfee.NewAppModule(app.IBCFeeKeeper),
feeabsmodule.NewAppModule(appCodec, app.FeeabsKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(tokenfactorytypes.ModuleName)),
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
Expand Down Expand Up @@ -812,6 +839,7 @@ func NewMigalooApp(
feeburnmoduletypes.ModuleName,
// additional non simd modules
ibctransfertypes.ModuleName,
feeabstypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
Expand Down Expand Up @@ -846,6 +874,7 @@ func NewMigalooApp(
packetforwardtypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
feeabstypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
ibchookstypes.ModuleName,
Expand Down Expand Up @@ -885,6 +914,7 @@ func NewMigalooApp(
packetforwardtypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
feeabstypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
tokenfactorytypes.ModuleName,
Expand Down Expand Up @@ -933,6 +963,7 @@ func NewMigalooApp(
FeeburnKeeper: &app.FeeBurnKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: keys[wasmtypes.StoreKey],
FeeabsKeeper: app.FeeabsKeeper,
},
)
if err != nil {
Expand Down Expand Up @@ -963,6 +994,7 @@ func NewMigalooApp(
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper
app.ScopedICQKeeper = scopedICQKeeper
app.ScopedFeeabsKeeper = scopedFeeabsKeeper

// set the contract keeper for the Ics20WasmHooks
app.Ics20WasmHooks.ContractKeeper = &app.WasmKeeper
Expand Down Expand Up @@ -1049,6 +1081,10 @@ func (app *MigalooApp) BlockedModuleAccountAddrs() map[string]bool {
if acc == alliancemoduletypes.ModuleName {
continue
}
// don't blacklist feeabs module account, so that it can hold ibc tokens
if acc == feeabstypes.ModuleName {
continue
}
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
}

Expand Down Expand Up @@ -1237,6 +1273,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(alliancemoduletypes.ModuleName).WithKeyTable(alliancemoduletypes.ParamKeyTable())
paramsKeeper.Subspace(feeburnmoduletypes.ModuleName)
paramsKeeper.Subspace(feeabstypes.ModuleName)

return paramsKeeper
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ require (
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.3
github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.1.1
github.com/golang/protobuf v1.5.4
github.com/osmosis-labs/fee-abstraction/v7 v7.0.0-20240408070113-b8791624f3be
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,9 @@ github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoD
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
Expand Down Expand Up @@ -854,6 +855,8 @@ github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnh
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA=
github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs=
github.com/osmosis-labs/fee-abstraction/v7 v7.0.0-20240408070113-b8791624f3be h1:CBgtICAJK19dIBOfXMUAa8H/f78iFCUmVSy5Sk8HTdw=
github.com/osmosis-labs/fee-abstraction/v7 v7.0.0-20240408070113-b8791624f3be/go.mod h1:y/N5kGya7AQm/kfBvlhi2CmwjsXMXGHOuRQ1WH7jK8Y=
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
Expand Down

0 comments on commit 41e2e6a

Please sign in to comment.