Skip to content

Commit

Permalink
Add InflateDao function to EndBlocker
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Dusek committed May 12, 2023
1 parent 978e42e commit 2cdae63
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func New( // nolint:funlen // app new cosmos func
&app.AccountKeeper,
&app.DistrKeeper,
&app.GovKeeper,
&app.MintKeeper,
&app.StakingKeeper,
)

Expand Down
4 changes: 4 additions & 0 deletions x/dao/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ func endBlocker(ctx sdk.Context, k keeper.Keeper) (err error) {
}
}

if err = k.InflateDao(ctx); err != nil {
return err
}

return err
}
3 changes: 3 additions & 0 deletions x/dao/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type (
accountKeeper types.AccountKeeper
distributionKeeper types.DistributionKeeper
govKeeper types.GovKeeper
mintKeeper types.MintKeeper
stakingKeeper types.StakingKeeper
}
)
Expand All @@ -36,6 +37,7 @@ func NewKeeper(
accountKeeper types.AccountKeeper,
distributionKeeper types.DistributionKeeper,
govKeeper types.GovKeeper,
mintKeeper types.MintKeeper,
stakingKeeper types.StakingKeeper,
) *Keeper {
// set KeyTable if it has not already been set
Expand All @@ -57,6 +59,7 @@ func NewKeeper(
accountKeeper: accountKeeper,
distributionKeeper: distributionKeeper,
govKeeper: govKeeper,
mintKeeper: mintKeeper,
stakingKeeper: stakingKeeper,
}
}
Expand Down
27 changes: 27 additions & 0 deletions x/dao/keeper/mint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/onomyprotocol/onomy/x/dao/types"
)

// VoteAbstain votes abstain on all the proposals from the DAO account.
func (k Keeper) InflateDao(ctx sdk.Context) (err error) {
daoAddr := k.accountKeeper.GetModuleAddress(types.ModuleName)
daoBalance := k.bankKeeper.GetBalance(ctx, daoAddr, "nom")
minter := k.mintKeeper.GetMinter(ctx)
params := k.mintKeeper.GetParams(ctx)
minter.AnnualProvisions = minter.NextAnnualProvisions(params, daoBalance.Amount)

// mint coins, update supply
mintedCoin := minter.BlockProvision(params)
mintedCoins := sdk.NewCoins(mintedCoin)

err = k.bankKeeper.MintCoins(ctx, types.ModuleName, mintedCoins)
if err != nil {
panic(err)
}

return err
}
8 changes: 8 additions & 0 deletions x/dao/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand All @@ -24,6 +25,7 @@ type AccountKeeper interface {
// BankKeeper defines the contract needed to be fulfilled for banking and supply dependencies.
type BankKeeper interface {
GetAllBalances(sdk.Context, sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
SendCoinsFromAccountToModule(sdk.Context, sdk.AccAddress, string, sdk.Coins) error
SendCoinsFromModuleToAccount(sdk.Context, string, sdk.AccAddress, sdk.Coins) error
SendCoinsFromModuleToModule(ctx sdk.Context, senderPool, recipientPool string, amt sdk.Coins) error
Expand All @@ -43,6 +45,12 @@ type GovKeeper interface {
IterateProposals(sdk.Context, func(proposal govtypes.Proposal) bool)
}

// MintKeeper expected mint keeper.
type MintKeeper interface {
GetMinter(ctx sdk.Context) (minter minttypes.Minter)
GetParams(ctx sdk.Context) (params minttypes.Params)
}

// StakingKeeper expected staking keeper.
type StakingKeeper interface {
BondDenom(sdk.Context) string
Expand Down

0 comments on commit 2cdae63

Please sign in to comment.