Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Migrate `x/gov` fork from Atom One to Atom One SDK [#248](https://github.com/atomone-hub/atomone/pull/248)
- Add governors to `x/gov` module [#258](https://github.com/atomone-hub/atomone/pull/258)
- Prevent Oversight DAO from vetoing proposals that include a change to the Oversight DAO address [#275](https://github.com/atomone-hub/atomone/pull/275)
- Set chain-wide `MaxCommissionRate` and `MinCommissionRate` to 5% and update validator commission rates accordingly [#300](https://github.com/atomone-hub/atomone/pull/300)

### STATE BREAKING

Expand Down
40 changes: 40 additions & 0 deletions app/upgrades/v4/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
sdkgov "github.com/cosmos/cosmos-sdk/x/gov/types"
sdkgovv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

"github.com/atomone-hub/atomone/app/keepers"
v1 "github.com/atomone-hub/atomone/x/gov/types/v1"
Expand All @@ -43,6 +44,10 @@ func CreateUpgradeHandler(
return vm, err
}

if err := migrateValidatorsCommission(ctx, keepers.StakingKeeper); err != nil {
return vm, err
}

return vm, nil
}
}
Expand Down Expand Up @@ -573,3 +578,38 @@ func governorValSharesValueCodec(cdc codec.Codec) collcodec.ValueCodec[sdkgovv1.
return *v1.ConvertAtomOneGovernorValSharesToSDK(c), nil
})
}

// migrateValidatorsCommission sets the chain-wide commission to the constitutionally-mandated 5% and updates all existing validator's commission accordingly.
func migrateValidatorsCommission(ctx context.Context, stakingKeeper *stakingkeeper.Keeper) error {
// Set chain-wide commission to 5%
params, err := stakingKeeper.GetParams(ctx)
if err != nil {
return err
}

fivePercent := math.LegacyMustNewDecFromStr("0.05")

params.MaxCommissionRate = fivePercent
params.MinCommissionRate = fivePercent
if err := stakingKeeper.SetParams(ctx, params); err != nil {
return err
}

// Update all existing validators' commission to 5%
validators, err := stakingKeeper.GetAllValidators(ctx)
if err != nil {
return err
}
for _, validator := range validators {
// leaving MaxRate and MaxChangeRate unchanged as validator-defined values.
// In any case, the chain-wide MaxCommissionRate = MinCommissionRate = 5% would still prevent validators from changing their
// commission rate to anything other than 5%.
validator.Commission.Rate = fivePercent

if err := stakingKeeper.SetValidator(ctx, validator); err != nil {
return err
}
}

return nil
}
Loading