Skip to content

Commit

Permalink
add feeshare module
Browse files Browse the repository at this point in the history
  • Loading branch information
hard-nett committed Jul 9, 2023
1 parent bcf012d commit 979dfc3
Show file tree
Hide file tree
Showing 67 changed files with 10,916 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# CODEOWNERS: https://help.github.com/articles/about-codeowners/

# Primary repo maintainers
* @terpnetwork
* @ethanfrey
* @alpe
* @discoverdefiteam
5 changes: 5 additions & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
"github.com/cosmos/ibc-go/v7/modules/core/keeper"
feeshareante "github.com/terpnetwork/terp-core/v2/x/feeshare/ante"
feesharekeeper "github.com/terpnetwork/terp-core/v2/x/feeshare/keeper"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand All @@ -20,6 +22,8 @@ type HandlerOptions struct {

IBCKeeper *keeper.Keeper
WasmConfig *wasmTypes.WasmConfig
FeeShareKeeper feesharekeeper.Keeper
BankKeeperFork feeshareante.BankKeeper
TXCounterStoreKey storetypes.StoreKey
}

Expand Down Expand Up @@ -50,6 +54,7 @@ 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.BankKeeperFork, options.FeeShareKeeper),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
Expand Down
26 changes: 24 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
packetforward "github.com/strangelove-ventures/packet-forward-middleware/v7/router"
packetforwardkeeper "github.com/strangelove-ventures/packet-forward-middleware/v7/router/keeper"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v7/router/types"
"github.com/terpnetwork/terp-core/v2/x/feeshare"
"github.com/terpnetwork/terp-core/v2/x/ibchooks"
ibchookskeeper "github.com/terpnetwork/terp-core/v2/x/ibchooks/keeper"
ibchookstypes "github.com/terpnetwork/terp-core/v2/x/ibchooks/types"
Expand Down Expand Up @@ -133,6 +134,8 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
ibcmock "github.com/cosmos/ibc-go/v7/testing/mock"
feesharekeeper "github.com/terpnetwork/terp-core/v2/x/feeshare/keeper"
feesharetypes "github.com/terpnetwork/terp-core/v2/x/feeshare/types"

"github.com/spf13/cast"

Expand Down Expand Up @@ -276,6 +279,7 @@ var (
icq.AppModuleBasic{},
ibchooks.AppModuleBasic{},
packetforward.AppModuleBasic{},
feeshare.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -331,6 +335,7 @@ type TerpApp struct {
FeeGrantKeeper feegrantkeeper.Keeper
GroupKeeper groupkeeper.Keeper
NFTKeeper nftkeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper

IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
Expand Down Expand Up @@ -415,6 +420,7 @@ func NewTerpApp(
icqtypes.StoreKey,
packetforwardtypes.StoreKey,
ibchookstypes.StoreKey,
feesharetypes.StoreKey,
icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
)
Expand Down Expand Up @@ -747,6 +753,16 @@ func NewTerpApp(
wasmOpts...,
)

app.FeeShareKeeper = feesharekeeper.NewKeeper(
app.keys[feesharetypes.StoreKey],
appCodec,
app.BankKeeper,
app.WasmKeeper,
app.AccountKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// The gov proposal types can be individually enabled
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
Expand Down Expand Up @@ -832,6 +848,7 @@ func NewTerpApp(
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
feeshare.NewAppModule(app.FeeShareKeeper, app.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ibc.NewAppModule(app.IBCKeeper),
transfer.NewAppModule(app.TransferKeeper),
Expand Down Expand Up @@ -861,6 +878,7 @@ func NewTerpApp(
ibcfeetypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
feesharetypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
)
Expand All @@ -879,6 +897,7 @@ func NewTerpApp(
ibcfeetypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
feesharetypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
)
Expand All @@ -905,6 +924,7 @@ func NewTerpApp(
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
ibchookstypes.ModuleName,
feesharetypes.ModuleName,
// wasm after ibc transfer
wasm.ModuleName,
}
Expand Down Expand Up @@ -938,8 +958,7 @@ func NewTerpApp(
// NOTE: this is not required apps that don't use the simulator for fuzz testing
// transactions
overrideModules := map[string]module.AppModuleSimulation{
authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
}
authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName))}
app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules)

app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -1043,6 +1062,8 @@ func (app *TerpApp) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtype
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
FeeShareKeeper: app.FeeShareKeeper,
BankKeeperFork: app.BankKeeper, // since we need extra methods
IBCKeeper: app.IBCKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: txCounterStoreKey,
Expand Down Expand Up @@ -1246,6 +1267,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icqtypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName)
paramsKeeper.Subspace(feesharetypes.ModuleName)
paramsKeeper.Subspace(wasm.ModuleName)

return paramsKeeper
Expand Down
9 changes: 8 additions & 1 deletion app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ type Upgrade struct {
}

// Returns "uterpx" if the chain is 90u-, else returns the standard uterp token denom.
func GetChainsDenomToken(chainID string) string {
func GetChainsFeeDenomToken(chainID string) string {
if strings.HasPrefix(chainID, "90u-") {
return "uthiolx"
}
return "uthiol"
}

func GetChainsBondDenomToken(chainID string) string {
if strings.HasPrefix(chainID, "90u-") {
return "uterpx"
}
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/v2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
store "github.com/cosmos/cosmos-sdk/store/types"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v7/router/types"
"github.com/terpnetwork/terp-core/v2/app/upgrades"
feesharetypes "github.com/terpnetwork/terp-core/v2/x/feeshare/types"
ibchookstypes "github.com/terpnetwork/terp-core/v2/x/ibchooks/types"
)

Expand All @@ -17,6 +18,7 @@ var Upgrade = upgrades.Upgrade{
Added: []string{
ibchookstypes.StoreKey,
packetforwardtypes.StoreKey,
feesharetypes.ModuleName,
},
},
}
17 changes: 15 additions & 2 deletions app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v7/router/types"
feesharetypes "github.com/terpnetwork/terp-core/v2/x/feeshare/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -23,8 +24,9 @@ func CreateV2UpgradeHandler(
// the above is https://github.com/cosmos/ibc-go/blob/v5.1.0/docs/migrations/v3-to-v4.md
logger := ctx.Logger().With("upgrade", UpgradeName)

nativeDenom := upgrades.GetChainsDenomToken(ctx.ChainID())
logger.Info(fmt.Sprintf("With native denom %s", nativeDenom))
nativeFeeDenom := upgrades.GetChainsFeeDenomToken(ctx.ChainID())
nativeBondDenom := upgrades.GetChainsBondDenomToken(ctx.ChainID())
logger.Info(fmt.Sprintf("With native fee denom %s and native gas denom %s", nativeFeeDenom, nativeBondDenom))

// Run migrations
versionMap, err := mm.RunMigrations(ctx, cfg, vm)
Expand All @@ -34,6 +36,17 @@ func CreateV2UpgradeHandler(
// Packet Forward middleware initial params
keepers.PacketForwardKeeper.SetParams(ctx, packetforwardtypes.DefaultParams())

// FeeShare
newFeeShareParams := feesharetypes.Params{
EnableFeeShare: true,
DeveloperShares: sdk.NewDecWithPrec(50, 2), // = 50%
AllowedDenoms: []string{nativeFeeDenom, nativeBondDenom},
}
if err := keepers.FeeShareKeeper.SetParams(ctx, newFeeShareParams); err != nil {
return nil, err
}
logger.Info("set feeshare params")

return versionMap, err
}

Expand Down
30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ go 1.20
require (
github.com/CosmWasm/wasmd v0.40.2
github.com/CosmWasm/wasmvm v1.2.4 // indirect
github.com/cometbft/cometbft v0.37.1
github.com/cometbft/cometbft-db v0.7.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cometbft/cometbft v0.37.2
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.3
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.10 // indirect
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/iavl v0.20.0 // indirect
github.com/cosmos/ibc-go/v7 v7.0.1
github.com/cosmos/ics23/go v0.9.1-0.20221207100636-b1abd8678aab // indirect
github.com/cosmos/ibc-go/v7 v7.2.0
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.3
github.com/google/gofuzz v1.2.0 // indirect
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.15.0
github.com/prometheus/client_golang v1.16.0
github.com/rakyll/statik v0.1.7 // indirect
github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.3
github.com/stretchr/testify v1.8.4
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.56.1
gopkg.in/yaml.v2 v2.4.0 // indirect
)

Expand All @@ -47,7 +47,7 @@ require (

require (
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.19.0 // indirect
cloud.google.com/go/compute v1.19.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.29.0 // indirect
Expand Down Expand Up @@ -125,6 +125,7 @@ require (
github.com/klauspost/compress v1.16.3 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.7.16 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -142,15 +143,14 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.29.1 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
Expand All @@ -171,7 +171,7 @@ require (
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
nhooyr.io/websocket v1.8.7 // indirect
pgregory.net/rapid v0.5.5 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Expand Down
Loading

0 comments on commit 979dfc3

Please sign in to comment.