-
Notifications
You must be signed in to change notification settings - Fork 28
/
migrate.go
69 lines (60 loc) · 2.3 KB
/
migrate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package v152
import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/irisnet/irismod/modules/farm/types"
"github.com/irisnet/irismod/types/exported"
)
// Parameter store keys
var (
DefaultPoolCreationFee = sdk.NewCoin("uiris", sdkmath.NewIntWithDecimal(2000, 6))
DefaultTaxRate = sdk.NewDecWithPrec(4, 1)
)
type (
FarmKeeper interface {
SetParams(ctx sdk.Context, params types.Params) error
}
Params struct {
PoolCreationFee sdk.Coin `protobuf:"bytes,1,opt,name=pool_creation_fee,json=poolCreationFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Coin" json:"pool_creation_fee"`
MaxRewardCategories uint32 `protobuf:"varint,2,opt,name=max_reward_categories,json=maxRewardCategories,proto3" json:"max_reward_categories,omitempty"`
TaxRate sdk.Dec `protobuf:"bytes,3,opt,name=tax_rate,json=taxRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"tax_rate"`
}
)
func Migrate(
ctx sdk.Context,
k FarmKeeper,
ak types.AccountKeeper,
legacySubspace exported.Subspace,
) error {
params := GetLegacyParams(ctx, legacySubspace)
newParams := types.Params{
MaxRewardCategories: params.MaxRewardCategories,
PoolCreationFee: DefaultPoolCreationFee,
TaxRate: DefaultTaxRate,
}
if err := k.SetParams(ctx, newParams); err != nil {
return err
}
//Grant burner permissions to the farm module account
acc := ak.GetModuleAccount(ctx, types.ModuleName)
if !acc.HasPermission(authtypes.Burner) {
moduleAcc, _ := acc.(*authtypes.ModuleAccount)
moduleAcc.Permissions = append(moduleAcc.Permissions, authtypes.Burner)
}
ak.SetModuleAccount(ctx, acc)
return nil
}
// GetLegacyParams gets the parameters for the coinswap module.
func GetLegacyParams(ctx sdk.Context, legacySubspace exported.Subspace) Params {
var swapParams Params
legacySubspace.GetParamSet(ctx, &swapParams)
return swapParams
}
// ParamSetPairs implements paramtypes.KeyValuePairs
func (p *Params) ParamSetPairs() exported.ParamSetPairs {
return exported.ParamSetPairs{
exported.NewParamSetPair(types.KeyPoolCreationFee, &p.PoolCreationFee, nil),
exported.NewParamSetPair(types.KeyMaxRewardCategories, &p.MaxRewardCategories, nil),
}
}