Skip to content

Commit

Permalink
feat: include KYVE protocol in bonding ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed Dec 16, 2022
1 parent c1947de commit eeee6c8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func NewSimApp(
)
app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName,
nil, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName,
)
app.DistrKeeper = distrkeeper.NewKeeper(
appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
Expand Down
41 changes: 27 additions & 14 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ import (

// Keeper of the mint store
type Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
paramSpace paramtypes.Subspace
stakingKeeper types.StakingKeeper
bankKeeper types.BankKeeper
feeCollectorName string
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
paramSpace paramtypes.Subspace
stakingKeeper types.StakingKeeper
protocolStakingKeeper types.ProtocolStakingKeeper
bankKeeper types.BankKeeper
feeCollectorName string
}

// NewKeeper creates a new mint Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper,
sk types.StakingKeeper, psk types.ProtocolStakingKeeper, ak types.AccountKeeper, bk types.BankKeeper,
feeCollectorName string,
) Keeper {
// ensure mint module account is set
Expand All @@ -38,12 +39,13 @@ func NewKeeper(
}

return Keeper{
cdc: cdc,
storeKey: key,
paramSpace: paramSpace,
stakingKeeper: sk,
bankKeeper: bk,
feeCollectorName: feeCollectorName,
cdc: cdc,
storeKey: key,
paramSpace: paramSpace,
stakingKeeper: sk,
protocolStakingKeeper: psk,
bankKeeper: bk,
feeCollectorName: feeCollectorName,
}
}

Expand Down Expand Up @@ -91,7 +93,18 @@ func (k Keeper) StakingTokenSupply(ctx sdk.Context) math.Int {
// BondedRatio implements an alias call to the underlying staking keeper's
// BondedRatio to be used in BeginBlocker.
func (k Keeper) BondedRatio(ctx sdk.Context) sdk.Dec {
return k.stakingKeeper.BondedRatio(ctx)
totalSupply := k.stakingKeeper.StakingTokenSupply(ctx)
if !totalSupply.IsPositive() {
return sdk.ZeroDec()
}

bondedTokens := sdk.NewDecFromInt(k.stakingKeeper.TotalBondedTokens(ctx))
protocolBondedTokens := sdk.ZeroDec()
if k.protocolStakingKeeper != nil {
protocolBondedTokens = sdk.NewDecFromInt(k.protocolStakingKeeper.TotalBondedTokens(ctx))
}

return bondedTokens.Add(protocolBondedTokens).QuoInt(totalSupply)
}

// MintCoins implements an alias call to the underlying supply keeper's
Expand Down
7 changes: 6 additions & 1 deletion x/mint/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import (
// StakingKeeper defines the expected staking keeper
type StakingKeeper interface {
StakingTokenSupply(ctx sdk.Context) math.Int
BondedRatio(ctx sdk.Context) sdk.Dec
TotalBondedTokens(ctx sdk.Context) math.Int
}

// ProtocolStakingKeeper defines the expected KYVE protocol staking keeper
type ProtocolStakingKeeper interface {
TotalBondedTokens(ctx sdk.Context) math.Int
}

// AccountKeeper defines the contract required for account APIs.
Expand Down

0 comments on commit eeee6c8

Please sign in to comment.