Skip to content

Commit

Permalink
Merge pull request #216 from neutron-org/feat/NTRN-430-commission-for…
Browse files Browse the repository at this point in the history
…-tokenfactory

feat: NTRN-430. Add commission for Token Factory
  • Loading branch information
Andrew Zavgorodny authored Apr 21, 2023
2 parents d83791b + a37eb66 commit a735ee5
Show file tree
Hide file tree
Showing 28 changed files with 2,074 additions and 2,368 deletions.
14 changes: 10 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/neutron-org/neutron/app/upgrades"
v044 "github.com/neutron-org/neutron/app/upgrades/v0.4.4"
v3 "github.com/neutron-org/neutron/app/upgrades/v3"
"github.com/neutron-org/neutron/x/cron"

Expand Down Expand Up @@ -172,7 +173,7 @@ func GetEnabledProposals() []wasm.ProposalType {
}

var (
Upgrades = []upgrades.Upgrade{v3.Upgrade}
Upgrades = []upgrades.Upgrade{v3.Upgrade, v044.Upgrade}

// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
Expand Down Expand Up @@ -893,9 +894,14 @@ func (app *App) setupUpgradeHandlers() {
upgrade.CreateUpgradeHandler(
app.mm,
app.configurator,
app.InterchainQueriesKeeper,
app.CronKeeper,
app.TokenFactoryKeeper,
&upgrades.UpgradeKeepers{
FeeBurnerKeeper: app.FeeBurnerKeeper,
CronKeeper: app.CronKeeper,
IcqKeeper: app.InterchainQueriesKeeper,
TokenFactoryKeeper: app.TokenFactoryKeeper,
SlashingKeeper: app.SlashingKeeper,
ParamsKeeper: app.ParamsKeeper,
},
),
)
}
Expand Down
8 changes: 6 additions & 2 deletions app/proposals_allowlisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
feerefundertypes "github.com/neutron-org/neutron/x/feerefunder/types"
interchainqueriestypes "github.com/neutron-org/neutron/x/interchainqueries/types"
interchaintxstypes "github.com/neutron-org/neutron/x/interchaintxs/types"
tokenfactorytypes "github.com/neutron-org/neutron/x/tokenfactory/types"
)

func IsConsumerProposalAllowlisted(content govtypes.Content) bool {
Expand Down Expand Up @@ -72,8 +73,11 @@ var WhitelistedParams = map[paramChangeKey]struct{}{
{Subspace: interchainqueriestypes.ModuleName, Key: string(interchainqueriestypes.KeyQueryDeposit)}: {},
{Subspace: interchainqueriestypes.ModuleName, Key: string(interchainqueriestypes.KeyTxQueryRemovalLimit)}: {},
// feeburner
{Subspace: feeburnertypes.ModuleName, Key: string(feeburnertypes.KeyReserveAddress)}: {},
{Subspace: feeburnertypes.ModuleName, Key: string(feeburnertypes.KeyNeutronDenom)}: {},
{Subspace: feeburnertypes.ModuleName, Key: string(feeburnertypes.KeyTreasuryAddress)}: {},
{Subspace: feeburnertypes.ModuleName, Key: string(feeburnertypes.KeyNeutronDenom)}: {},
// tokenfactory
{Subspace: tokenfactorytypes.ModuleName, Key: string(tokenfactorytypes.KeyDenomCreationFee)}: {},
{Subspace: tokenfactorytypes.ModuleName, Key: string(tokenfactorytypes.KeyFeeCollectorAddress)}: {},
// cron
{Subspace: crontypes.ModuleName, Key: string(crontypes.KeySecurityAddress)}: {},
{Subspace: crontypes.ModuleName, Key: string(crontypes.KeyLimit)}: {},
Expand Down
15 changes: 14 additions & 1 deletion app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package upgrades
import (
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/types/module"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
cronkeeper "github.com/neutron-org/neutron/x/cron/keeper"
feeburnerkeeper "github.com/neutron-org/neutron/x/feeburner/keeper"
icqkeeper "github.com/neutron-org/neutron/x/interchainqueries/keeper"
tokenfactorykeeper "github.com/neutron-org/neutron/x/tokenfactory/keeper"
)
Expand All @@ -19,8 +22,18 @@ type Upgrade struct {
UpgradeName string

// CreateUpgradeHandler defines the function that creates an upgrade handler
CreateUpgradeHandler func(*module.Manager, module.Configurator, icqkeeper.Keeper, cronkeeper.Keeper, *tokenfactorykeeper.Keeper) upgradetypes.UpgradeHandler
CreateUpgradeHandler func(*module.Manager, module.Configurator, *UpgradeKeepers) upgradetypes.UpgradeHandler

// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}

type UpgradeKeepers struct {
// keepers
IcqKeeper icqkeeper.Keeper
CronKeeper cronkeeper.Keeper
TokenFactoryKeeper *tokenfactorykeeper.Keeper
FeeBurnerKeeper *feeburnerkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
ParamsKeeper paramskeeper.Keeper
}
15 changes: 15 additions & 0 deletions app/upgrades/v0.4.4/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v044

import (
"github.com/neutron-org/neutron/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrades name.
UpgradeName = "v0.4.4"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
}
58 changes: 58 additions & 0 deletions app/upgrades/v0.4.4/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package v044

import (
"errors"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

feeburnertypes "github.com/neutron-org/neutron/x/feeburner/types"
tokenfactorytypes "github.com/neutron-org/neutron/x/tokenfactory/types"

"github.com/neutron-org/neutron/app/upgrades"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *upgrades.UpgradeKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting module migrations...")
vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}

ctx.Logger().Info("Migrating SlashingKeeper Params...")
oldSlashingParams := keepers.SlashingKeeper.GetParams(ctx)
oldSlashingParams.SignedBlocksWindow = int64(36000)

keepers.SlashingKeeper.SetParams(ctx, oldSlashingParams)

ctx.Logger().Info("Migrating FeeBurner Params...")
s, ok := keepers.ParamsKeeper.GetSubspace(feeburnertypes.ModuleName)
if !ok {
return nil, errors.New("global fee burner params subspace not found")
}
var reserveAddress string
s.Get(ctx, feeburnertypes.KeyReserveAddress, &reserveAddress)

var neutronDenom string
s.Get(ctx, feeburnertypes.KeyNeutronDenom, &neutronDenom)

feeburnerDefaultParams := feeburnertypes.DefaultParams()
feeburnerDefaultParams.TreasuryAddress = reserveAddress
feeburnerDefaultParams.NeutronDenom = neutronDenom
keepers.FeeBurnerKeeper.SetParams(ctx, feeburnerDefaultParams)

ctx.Logger().Info("Migrating TokenFactory Params...")
tokenfactoryDefaultParams := tokenfactorytypes.DefaultParams()
tokenfactoryDefaultParams.FeeCollectorAddress = reserveAddress
keepers.TokenFactoryKeeper.SetParams(ctx, tokenfactoryDefaultParams)

ctx.Logger().Info("Upgrade complete")
return vm, err
}
}
14 changes: 5 additions & 9 deletions app/upgrades/v3/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/neutron-org/neutron/app/upgrades"

cronkeeper "github.com/neutron-org/neutron/x/cron/keeper"
crontypes "github.com/neutron-org/neutron/x/cron/types"
icqkeeper "github.com/neutron-org/neutron/x/interchainqueries/keeper"
icqtypes "github.com/neutron-org/neutron/x/interchainqueries/types"
tokenfactorykeeper "github.com/neutron-org/neutron/x/tokenfactory/keeper"
tokenfactorytypes "github.com/neutron-org/neutron/x/tokenfactory/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
icqKeeper icqkeeper.Keeper,
cronKeeper cronkeeper.Keeper,
tokenfactoryKeeper *tokenfactorykeeper.Keeper,
keepers *upgrades.UpgradeKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting module migrations...")

// todo: FIXME
icqKeeper.SetParams(ctx, icqtypes.DefaultParams())
cronKeeper.SetParams(ctx, crontypes.DefaultParams())
tokenfactoryKeeper.SetParams(ctx, tokenfactorytypes.DefaultParams())
keepers.IcqKeeper.SetParams(ctx, icqtypes.DefaultParams())
keepers.CronKeeper.SetParams(ctx, crontypes.DefaultParams())
keepers.TokenFactoryKeeper.SetParams(ctx, tokenfactorytypes.DefaultParams())

vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
Expand Down
Loading

0 comments on commit a735ee5

Please sign in to comment.