-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change wiring for mint and gov to use ProviderKeeper instead of Staki…
…ngKeeper
- Loading branch information
1 parent
51ad903
commit a0cedbe
Showing
5 changed files
with
198 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
// Iterates over the consensus-active validators by power. | ||
// The same as IterateBondedValidatorsByPower in the StakingKeeper, | ||
// but only returns the first MaxProviderConsensusValidators validators. | ||
// This is used to implement the interface of the staking keeper to interface with | ||
// modules that need to reference the consensus-active validators. | ||
func (k Keeper) IterateBondedValidatorsByPower(ctx context.Context, fn func(index int64, validator stakingtypes.ValidatorI) (stop bool)) error { | ||
maxProviderConsensusVals := k.GetMaxProviderConsensusValidators(sdk.UnwrapSDKContext(ctx)) | ||
counter := int64(0) | ||
return k.stakingKeeper.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) { | ||
if counter >= maxProviderConsensusVals { | ||
return true | ||
} | ||
counter++ | ||
return fn(index, validator) | ||
}) | ||
} | ||
|
||
// Gets the amount of bonded tokens, which is equal | ||
// to the amount of tokens of the consensus-active validators. | ||
// The same as TotalBondedTokens, but only counts | ||
// tokens of the first MaxProviderConsensusValidators validators. | ||
// This is used to implement the interface of the staking keeper to interface with | ||
// modules that need to reference the consensus-active validators. | ||
func (k Keeper) TotalBondedTokens(ctx context.Context) (math.Int, error) { | ||
// iterate through the bonded validators | ||
totalBondedTokens := math.ZeroInt() | ||
|
||
k.IterateBondedValidatorsByPower(ctx, func(_ int64, validator stakingtypes.ValidatorI) (stop bool) { | ||
tokens := validator.GetTokens() | ||
totalBondedTokens = totalBondedTokens.Add(tokens) | ||
return false | ||
}) | ||
|
||
return totalBondedTokens, nil | ||
} | ||
|
||
// The same as IterateDelegations in the StakingKeeper. | ||
// Necessary to implement the interface of the staking keeper to interface with | ||
// other modules. | ||
func (k Keeper) IterateDelegations(ctx context.Context, delegator sdk.AccAddress, fn func(index int64, delegation stakingtypes.DelegationI) (stop bool)) error { | ||
return k.stakingKeeper.IterateDelegations(ctx, delegator, fn) | ||
} | ||
|
||
// The same as StakingTotalSupply in the StakingKeeper. | ||
// Necessary to implement the interface of the staking keeper to interface with | ||
// other modules. | ||
func (k Keeper) StakingTokenSupply(ctx context.Context) (math.Int, error) { | ||
return k.stakingKeeper.StakingTokenSupply(ctx) | ||
} | ||
|
||
// Gets the ratio of tokens staked to validators active in the consensus | ||
// to the total supply of tokens. | ||
// Same as BondedRatio in the StakingKeeper, but only counts | ||
// tokens of the first MaxProviderConsensusValidators bonded validators. | ||
func (k Keeper) BondedRatio(ctx context.Context) (math.LegacyDec, error) { | ||
totalSupply, err := k.StakingTokenSupply(ctx) | ||
if err != nil { | ||
return math.LegacyZeroDec(), err | ||
} | ||
|
||
bondedTokens, err := k.TotalBondedTokens(ctx) | ||
if err != nil { | ||
return math.LegacyZeroDec(), err | ||
} | ||
|
||
if !totalSupply.IsPositive() { | ||
return math.LegacyZeroDec(), nil | ||
} | ||
|
||
return math.LegacyNewDecFromInt(bondedTokens).QuoInt(totalSupply), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters