|
| 1 | +//nolint:revive,stylecheck // versioning |
| 2 | +package v_1_2_0 |
| 3 | + |
| 4 | +import ( |
| 5 | + "context" |
| 6 | + |
| 7 | + upgradetypes "cosmossdk.io/x/upgrade/types" |
| 8 | + |
| 9 | + "github.com/cosmos/cosmos-sdk/types/module" |
| 10 | + |
| 11 | + "github.com/piplabs/story/client/app/keepers" |
| 12 | + estypes "github.com/piplabs/story/client/x/evmstaking/types" |
| 13 | + "github.com/piplabs/story/lib/errors" |
| 14 | + "github.com/piplabs/story/lib/log" |
| 15 | +) |
| 16 | + |
| 17 | +func CreateUpgradeHandler( |
| 18 | + _ *module.Manager, |
| 19 | + _ module.Configurator, |
| 20 | + keepers *keepers.Keepers, |
| 21 | +) upgradetypes.UpgradeHandler { |
| 22 | + return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { |
| 23 | + log.Info(ctx, "Start upgrade v1.2.0") |
| 24 | + |
| 25 | + oldParams, err := keepers.EvmStakingKeeper.GetParams(ctx) |
| 26 | + if err != nil { |
| 27 | + return vm, errors.Wrap(err, "get evm staking params") |
| 28 | + } |
| 29 | + |
| 30 | + if err = keepers.EvmStakingKeeper.SetParams(ctx, estypes.Params{ |
| 31 | + MaxWithdrawalPerBlock: oldParams.MaxWithdrawalPerBlock, |
| 32 | + MaxSweepPerBlock: oldParams.MaxSweepPerBlock, |
| 33 | + MinPartialWithdrawalAmount: oldParams.MinPartialWithdrawalAmount, |
| 34 | + RefundFeeBps: InitialRefundFeeBps, |
| 35 | + RefundPeriod: InitialRefundPeriod, |
| 36 | + }); err != nil { |
| 37 | + return vm, errors.Wrap(err, "set evm staking params") |
| 38 | + } |
| 39 | + |
| 40 | + newParams, err := keepers.EvmStakingKeeper.GetParams(ctx) |
| 41 | + if err != nil { |
| 42 | + return vm, errors.Wrap(err, "get evm staking params") |
| 43 | + } |
| 44 | + |
| 45 | + if newParams.RefundFeeBps != InitialRefundFeeBps || newParams.RefundPeriod != InitialRefundPeriod { |
| 46 | + return vm, errors.Wrap(err, "set new evm staking params") |
| 47 | + } |
| 48 | + |
| 49 | + if newParams.MaxWithdrawalPerBlock != oldParams.MaxWithdrawalPerBlock || |
| 50 | + newParams.MaxSweepPerBlock != oldParams.MaxSweepPerBlock || |
| 51 | + newParams.MinPartialWithdrawalAmount != oldParams.MinPartialWithdrawalAmount { |
| 52 | + return vm, errors.Wrap(err, "set existing evm staking params") |
| 53 | + } |
| 54 | + |
| 55 | + log.Info(ctx, "Upgrade v1.2.0 complete") |
| 56 | + |
| 57 | + return vm, nil |
| 58 | + } |
| 59 | +} |
0 commit comments