Skip to content

Commit

Permalink
support custom inflationCalculationFn
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Dec 18, 2024
1 parent 9431cf6 commit 1356372
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 1 addition & 2 deletions x/mint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#20363](https://github.com/cosmos/cosmos-sdk/pull/20363) Deprecated InflationCalculationFn in favor of MintFn, `keeper.DefaultMintFn` wrapper must be used in order to continue using it in `NewAppModule`. This is not breaking for depinject users, as both `MintFn` and `InflationCalculationFn` are accepted.
* [#19367](https://github.com/cosmos/cosmos-sdk/pull/19398) `appmodule.Environment` is received on the Keeper to get access to different application services.
* [#21858](https://github.com/cosmos/cosmos-sdk/pull/21858) `NewKeeper` now returns a pointer to `Keeper`.
* [#21858](https://github.com/cosmos/cosmos-sdk/pull/21858) `DefaultMintFn` now takes `StakingKeeper` and `MintKeeper` as arguments to avoid staking keeper being required by mint.
* [#21858](https://github.com/cosmos/cosmos-sdk/pull/21858), [#22979](https://github.com/cosmos/cosmos-sdk/pull/22979) `DefaultMintFn` now takes `StakingKeeper` and `MintKeeper` as arguments to avoid staking keeper being required by mint.
* `SetMintFn` is used to replace the default minting function.
* `InflationCalculationFn` is not passed through depinject any longer, a MintFn is required instead.
19 changes: 15 additions & 4 deletions x/mint/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,22 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
return ModuleOutputs{MintKeeper: k, Module: m, EpochHooks: epochstypes.EpochHooksWrapper{EpochHooks: m}}
}

func InvokeSetMintFn(mintKeeper *keeper.Keeper, mintFn types.MintFn, stakingKeeper types.StakingKeeper) error {
if mintFn == nil && stakingKeeper == nil {
return fmt.Errorf("custom minting function or staking keeper must be supplied or available")
func InvokeSetMintFn(
mintKeeper *keeper.Keeper,
stakingKeeper types.StakingKeeper,
mintFn types.MintFn,
inflationCalculationFn types.InflationCalculationFn,
) error {
if mintFn == nil && stakingKeeper == nil && inflationCalculationFn == nil {
return fmt.Errorf("custom minting function, inflation calculation function or staking keeper must be supplied or available")
} else if mintFn != nil && inflationCalculationFn != nil {
return fmt.Errorf("cannot set both custom minting function and inflation calculation function")
} else if mintFn == nil {
mintFn = keeper.DefaultMintFn(types.DefaultInflationCalculationFn, stakingKeeper, mintKeeper)
if inflationCalculationFn != nil && stakingKeeper != nil {
mintFn = keeper.DefaultMintFn(inflationCalculationFn, stakingKeeper, mintKeeper)
} else {
mintFn = keeper.DefaultMintFn(types.DefaultInflationCalculationFn, stakingKeeper, mintKeeper)
}
}

return mintKeeper.SetMintFn(mintFn)
Expand Down

0 comments on commit 1356372

Please sign in to comment.