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

refactor: migrate farm params #361

Merged
merged 9 commits into from
Jun 14, 2023
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
google.golang.org/grpc v1.54.0
google.golang.org/protobuf v1.30.0
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.3.0
)

require (
Expand Down Expand Up @@ -163,7 +164,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v0.5.5 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace (
Expand Down
3 changes: 1 addition & 2 deletions modules/coinswap/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/irisnet/irismod/modules/coinswap/types"
)

// GetParams sets the x/staking module parameters.
// GetParams sets the coinswap module parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.ParamsKey))
Expand All @@ -19,7 +19,6 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
}

// SetParams sets the parameters for the coinswap module.
// SetParams sets the x/staking module parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
if err := params.Validate(); err != nil {
return err
Expand Down
31 changes: 1 addition & 30 deletions modules/coinswap/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@ package types
import (
"fmt"

"gopkg.in/yaml.v2"
"sigs.k8s.io/yaml"

sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// Parameter store keys
var (
KeyFee = []byte("Fee") // fee key
KeyPoolCreationFee = []byte("PoolCreationFee") // fee key
KeyTaxRate = []byte("TaxRate") // fee key
KeyStandardDenom = []byte("StandardDenom") // standard token denom key
KeyUnilateralLiquidityFee = []byte("UnilateralLiquidityFee") // fee key
)

// NewParams is the coinswap params constructor
Expand All @@ -28,25 +18,6 @@ func NewParams(fee, taxRate, unilateralLiquidityFee sdk.Dec, poolCreationFee sdk
}
}

// ParamKeyTable returns the TypeTable for coinswap module
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}

// ParamSetPairs implements paramtypes.KeyValuePairs
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyFee, &p.Fee, validateFee),
paramtypes.NewParamSetPair(KeyPoolCreationFee, &p.PoolCreationFee, validatePoolCreationFee),
paramtypes.NewParamSetPair(KeyTaxRate, &p.TaxRate, validateTaxRate),
paramtypes.NewParamSetPair(
KeyUnilateralLiquidityFee,
&p.UnilateralLiquidityFee,
validateUnilateraLiquiditylFee,
),
}
}

// DefaultParams returns the default coinswap module parameters
func DefaultParams() Params {
fee := sdk.NewDecWithPrec(3, 3)
Expand Down
33 changes: 33 additions & 0 deletions modules/coinswap/types/params_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package types

import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// Parameter store keys
var (
KeyFee = []byte("Fee") // fee key
KeyPoolCreationFee = []byte("PoolCreationFee") // fee key
KeyTaxRate = []byte("TaxRate") // fee key
KeyStandardDenom = []byte("StandardDenom") // standard token denom key
KeyUnilateralLiquidityFee = []byte("UnilateralLiquidityFee") // fee key
)

// ParamKeyTable returns the TypeTable for coinswap module
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}

// ParamSetPairs implements paramtypes.KeyValuePairs
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyFee, &p.Fee, validateFee),
paramtypes.NewParamSetPair(KeyPoolCreationFee, &p.PoolCreationFee, validatePoolCreationFee),
paramtypes.NewParamSetPair(KeyTaxRate, &p.TaxRate, validateTaxRate),
paramtypes.NewParamSetPair(
KeyUnilateralLiquidityFee,
&p.UnilateralLiquidityFee,
validateUnilateraLiquiditylFee,
),
}
}
23 changes: 23 additions & 0 deletions modules/farm/exported/exported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package exported

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

var (
NewParamSetPair = paramtypes.NewParamSetPair
)

type (
ParamSet = paramtypes.ParamSet
ParamSetPairs = paramtypes.ParamSetPairs

// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
}
)
13 changes: 3 additions & 10 deletions modules/farm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/irisnet/irismod/modules/farm/types"
)
Expand All @@ -17,13 +16,13 @@ import (
type Keeper struct {
cdc codec.Codec
storeKey storetypes.StoreKey
paramSpace paramstypes.Subspace
validateLPToken types.ValidateLPToken
bk types.BankKeeper
ak types.AccountKeeper
dk types.DistrKeeper
gk types.GovKeeper
feeCollectorName, communityPoolName string // name of the fee collector
authority string
}

func NewKeeper(
Expand All @@ -34,14 +33,8 @@ func NewKeeper(
dk types.DistrKeeper,
gk types.GovKeeper,
validateLPToken types.ValidateLPToken,
paramSpace paramstypes.Subspace,
feeCollectorName, communityPoolName string,
feeCollectorName, communityPoolName, authority string,
) Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(ParamKeyTable())
}

if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
Expand All @@ -59,9 +52,9 @@ func NewKeeper(
dk: dk,
gk: gk,
validateLPToken: validateLPToken,
paramSpace: paramSpace,
feeCollectorName: feeCollectorName,
communityPoolName: communityPoolName,
authority: authority,
}
}

Expand Down
19 changes: 14 additions & 5 deletions modules/farm/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
v152 "github.com/irisnet/irismod/modules/farm/migarations/v152"

"github.com/irisnet/irismod/modules/farm/exported"
v2 "github.com/irisnet/irismod/modules/farm/migrations/v2"
v3 "github.com/irisnet/irismod/modules/farm/migrations/v3"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
k Keeper
k Keeper
legacySubspace exported.Subspace
}

// NewMigrator returns a new Migrator.
func NewMigrator(k Keeper) Migrator {
return Migrator{k: k}
func NewMigrator(k Keeper, legacySubspace exported.Subspace) Migrator {
return Migrator{k: k, legacySubspace: legacySubspace}
}

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v152.Migrate(ctx, m.k, m.k.ak, m.k.paramSpace)
return v2.Migrate(ctx, m.k, m.k.ak, m.legacySubspace)
}

// Migrate1to2 migrates from version 2 to 3.
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v3.Migrate(ctx, m.k, m.legacySubspace)
}
Loading