Skip to content

Commit

Permalink
feat: add feeburn module to app
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Jan 5, 2024
1 parent 3349207 commit 73ebf15
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 412 deletions.
12 changes: 11 additions & 1 deletion app/ante.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package app

import (
errorsmod "cosmossdk.io/errors"
feeburnAnte "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/ante"
feeburnkeeper "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/keeper"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
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"
"github.com/cosmos/ibc-go/v7/modules/core/keeper"

Expand All @@ -18,6 +22,8 @@ type HandlerOptions struct {
ante.HandlerOptions

IBCKeeper *keeper.Keeper
FeeburnKeeper *feeburnkeeper.Keeper
BankKeeper bankkeeper.Keeper
WasmConfig *wasmTypes.WasmConfig
TXCounterStoreKey storetypes.StoreKey
}
Expand All @@ -39,6 +45,10 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
}

if options.FeeburnKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "Fee burn keeper is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
Expand All @@ -53,7 +63,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
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),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
28 changes: 26 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"

feeburnkeeper "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/keeper"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
Expand Down Expand Up @@ -130,6 +132,10 @@ import (
tokenfactorykeeper "github.com/terra-money/core/v2/x/tokenfactory/keeper"
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

feeburnmodule "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn"
feeburnmodulekeeper "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/keeper"
feeburnmoduletypes "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/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 @@ -161,7 +167,6 @@ const (
MockFeePort string = ibcmock.ModuleName + ibcfeetypes.ModuleName
)

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
NodeDir = ".migalood"
)
Expand Down Expand Up @@ -217,6 +222,7 @@ var (
router.AppModuleBasic{},
ica.AppModuleBasic{},
ibcfee.AppModuleBasic{},
feeburnmodule.AppModuleBasic{},
)

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

Expand Down Expand Up @@ -284,6 +291,7 @@ type MigalooApp struct {
RouterKeeper routerkeeper.Keeper
ContractKeeper *wasmkeeper.PermissionedKeeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
FeeBurnKeeper feeburnkeeper.Keeper

// IBC hooks
IBCHooksKeeper *ibchookskeeper.Keeper
Expand Down Expand Up @@ -349,7 +357,9 @@ func NewMigalooApp(
evidencetypes.StoreKey, icqtypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, wasmtypes.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, ibcfeetypes.StoreKey, tokenfactorytypes.StoreKey,
alliancemoduletypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey, ibchookstypes.StoreKey,
alliancemoduletypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey,
ibchookstypes.StoreKey,
feeburnmoduletypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -509,6 +519,13 @@ func NewMigalooApp(
scopedIBCKeeper,
)

app.FeeBurnKeeper = *feeburnmodulekeeper.NewKeeper(
appCodec,
keys[feeburnmoduletypes.StoreKey],
keys[feeburnmoduletypes.MemStoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName),
)

// 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 Down Expand Up @@ -743,6 +760,7 @@ func NewMigalooApp(
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
upgrade.NewAppModule(&app.UpgradeKeeper),
feeburnmodule.NewAppModule(appCodec, app.FeeBurnKeeper, app.AccountKeeper, app.BankKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
evidence.NewAppModule(app.EvidenceKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -783,6 +801,7 @@ func NewMigalooApp(
paramstypes.ModuleName,
vestingtypes.ModuleName,
icqtypes.ModuleName,
feeburnmoduletypes.ModuleName,
// additional non simd modules
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
Expand Down Expand Up @@ -813,6 +832,7 @@ func NewMigalooApp(
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
feeburnmoduletypes.ModuleName,
// additional non simd modules
icqtypes.ModuleName,
routertypes.ModuleName,
Expand Down Expand Up @@ -845,6 +865,7 @@ func NewMigalooApp(
minttypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
feeburnmoduletypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
icqtypes.ModuleName,
Expand Down Expand Up @@ -900,6 +921,8 @@ func NewMigalooApp(
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
IBCKeeper: app.IBCKeeper,
BankKeeper: app.BankKeeper,
FeeburnKeeper: &app.FeeBurnKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: keys[wasm.StoreKey],
},
Expand Down Expand Up @@ -1194,6 +1217,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(wasmtypes.ModuleName).WithKeyTable(wasmtypes.ParamKeyTable())
paramsKeeper.Subspace(routertypes.ModuleName).WithKeyTable(routertypes.ParamKeyTable())
paramsKeeper.Subspace(alliancemoduletypes.ModuleName).WithKeyTable(alliancemoduletypes.ParamKeyTable())
paramsKeeper.Subspace(feeburnmoduletypes.ModuleName)

return paramsKeeper
}
7 changes: 7 additions & 0 deletions app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ var (
Bech32PrefixConsPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
)

const (
// DisplayDenom defines the denomination displayed to users in client applications.
DisplayDenom = "whale"
// BaseDenom defines to the default denomination used in Evmos (staking, EVM, governance, etc.)
BaseDenom = "uwhale"
)

// SetAddressPrefixes builds the Config with Bech32 addressPrefix and publKeyPrefix for accounts, validators, and consensus nodes and verifies that addreeses have correct format.
// Not sealed yet
func SetAddressPrefixes() {
Expand Down
29 changes: 14 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ require (
github.com/CosmWasm/wasmd v0.45.0
github.com/cometbft/cometbft v0.37.4
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.47.7
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230906222317-d88d4028e5c9
github.com/cosmos/ibc-go/v7 v7.3.0
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/prometheus/client_golang v1.16.0
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.5.1
Expand All @@ -23,6 +26,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/terra-money/alliance v0.3.2
github.com/terra-money/core/v2 v2.5.0
google.golang.org/grpc v1.58.3
)

require (
Expand All @@ -31,7 +35,7 @@ require (
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/protobuf v1.3.2
github.com/google/s2a-go v0.1.4 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand All @@ -41,10 +45,17 @@ require (
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/zerolog v1.30.0 // indirect
golang.org/x/sync v0.3.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
)

require (
cosmossdk.io/errors v1.0.0
github.com/golang/protobuf v1.5.3
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v2 v2.4.0
)

require (
cloud.google.com/go v0.110.8 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
Expand All @@ -54,7 +65,6 @@ require (
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.6.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand All @@ -74,10 +84,8 @@ require (
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.10 // indirect
github.com/cosmos/iavl v0.20.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect
Expand All @@ -103,7 +111,6 @@ require (
github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
Expand All @@ -115,7 +122,6 @@ require (
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down Expand Up @@ -179,10 +185,7 @@ require (
google.golang.org/api v0.128.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v0.5.5 // indirect
Expand All @@ -192,17 +195,13 @@ require (
replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// downgraded to avoid some annoying warning messages
// should be fixed after sdk 0.47.3 and gogoproto 1.4.10
// https://github.com/cosmos/gogoproto/issues/66
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.8

// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
// Downgraded to avoid bugs in following commits which caused simulations to fail.
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

Expand Down
Loading

0 comments on commit 73ebf15

Please sign in to comment.