Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issuance module #599

Merged
merged 14 commits into from
Aug 17, 2020
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
export VERSION="$(git describe --tags --long | sed 's/v\(.*\)/\1/')"
export GO111MODULE=on
mkdir -p /tmp/logs /tmp/workspace/profiles
for pkg in $(go list ./... | grep -v '/simulation' | circleci tests split); do
for pkg in $(go list ./... | grep -v 'simulation\|migrate\|contrib' | circleci tests split); do
id=$(echo "$pkg" | sed 's|[/.]|_|g')
go test -mod=readonly -timeout 8m -race -coverprofile=/tmp/workspace/profiles/$id.out -covermode=atomic -tags='ledger test_ledger_mock' "$pkg" | tee "/tmp/logs/$id-$RANDOM.log"
done
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ test-basic: test
@go test ./app -run TestAppStateDeterminism -Enabled -Commit -NumBlocks=5 -BlockSize=200 -Seed 4 -v -timeout 2m

test:
@go test ./...
@go test $$(go list ./... | grep -v 'migrate\|contrib')

test-rest:
rest_test/./run_all_tests_from_make.sh
Expand Down
20 changes: 17 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/kava-labs/kava/x/cdp"
"github.com/kava-labs/kava/x/committee"
"github.com/kava-labs/kava/x/incentive"
"github.com/kava-labs/kava/x/issuance"
"github.com/kava-labs/kava/x/kavadist"
"github.com/kava-labs/kava/x/pricefeed"
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
Expand Down Expand Up @@ -80,6 +81,7 @@ var (
bep3.AppModuleBasic{},
kavadist.AppModuleBasic{},
incentive.AppModuleBasic{},
issuance.AppModuleBasic{},
)

// module account permissions
Expand All @@ -97,6 +99,7 @@ var (
cdp.SavingsRateMacc: {supply.Minter},
bep3.ModuleName: nil,
kavadist.ModuleName: {supply.Minter},
issuance.ModuleAccountName: {supply.Minter, supply.Burner},
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -140,6 +143,7 @@ type App struct {
bep3Keeper bep3.Keeper
kavadistKeeper kavadist.Keeper
incentiveKeeper incentive.Keeper
issuanceKeeper issuance.Keeper

// the module manager
mm *module.Manager
Expand All @@ -164,7 +168,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey,
gov.StoreKey, params.StoreKey, upgrade.StoreKey, evidence.StoreKey,
validatorvesting.StoreKey, auction.StoreKey, cdp.StoreKey, pricefeed.StoreKey,
bep3.StoreKey, kavadist.StoreKey, incentive.StoreKey, committee.StoreKey,
bep3.StoreKey, kavadist.StoreKey, incentive.StoreKey, issuance.StoreKey, committee.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)

Expand Down Expand Up @@ -193,6 +197,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
bep3Subspace := app.paramsKeeper.Subspace(bep3.DefaultParamspace)
kavadistSubspace := app.paramsKeeper.Subspace(kavadist.DefaultParamspace)
incentiveSubspace := app.paramsKeeper.Subspace(incentive.DefaultParamspace)
issuanceSubspace := app.paramsKeeper.Subspace(issuance.DefaultParamspace)

// add keepers
app.accountKeeper = auth.NewAccountKeeper(
Expand Down Expand Up @@ -350,6 +355,13 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
app.cdpKeeper,
app.accountKeeper,
)
app.issuanceKeeper = issuance.NewKeeper(
app.cdc,
keys[issuance.StoreKey],
issuanceSubspace,
app.accountKeeper,
app.supplyKeeper,
)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand Down Expand Up @@ -379,6 +391,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
kavadist.NewAppModule(app.kavadistKeeper, app.supplyKeeper),
incentive.NewAppModule(app.incentiveKeeper, app.accountKeeper, app.supplyKeeper),
committee.NewAppModule(app.committeeKeeper, app.accountKeeper),
issuance.NewAppModule(app.issuanceKeeper, app.accountKeeper, app.supplyKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -389,7 +402,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
app.mm.SetOrderBeginBlockers(
upgrade.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName,
validatorvesting.ModuleName, kavadist.ModuleName, auction.ModuleName, cdp.ModuleName,
bep3.ModuleName, incentive.ModuleName, committee.ModuleName,
bep3.ModuleName, incentive.ModuleName, committee.ModuleName, issuance.ModuleName,
)

app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName, pricefeed.ModuleName)
Expand All @@ -400,7 +413,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
staking.ModuleName, bank.ModuleName, slashing.ModuleName,
gov.ModuleName, mint.ModuleName, evidence.ModuleName,
pricefeed.ModuleName, cdp.ModuleName, auction.ModuleName,
bep3.ModuleName, kavadist.ModuleName, incentive.ModuleName, committee.ModuleName,
bep3.ModuleName, kavadist.ModuleName, incentive.ModuleName, committee.ModuleName, issuance.ModuleName,
supply.ModuleName, // calculates the total supply from account - should run after modules that modify accounts in genesis
crisis.ModuleName, // runs the invariants at genesis - should run after other modules
genutil.ModuleName, // genutils must occur after staking so that pools are properly initialized with tokens from genesis accounts.
Expand Down Expand Up @@ -430,6 +443,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
kavadist.NewAppModule(app.kavadistKeeper, app.supplyKeeper),
incentive.NewAppModule(app.incentiveKeeper, app.accountKeeper, app.supplyKeeper),
committee.NewAppModule(app.committeeKeeper, app.accountKeeper),
issuance.NewAppModule(app.issuanceKeeper, app.accountKeeper, app.supplyKeeper),
)

app.sm.RegisterStoreDecoders()
Expand Down
4 changes: 4 additions & 0 deletions app/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ const (
DefaultWeightMsgUpdatePrices int = 20
DefaultWeightMsgCdp int = 20
DefaultWeightMsgClaimReward int = 20
DefaultWeightMsgIssue int = 20
DefaultWeightMsgRedeem int = 20
DefaultWeightMsgBlock int = 20
DefaultWeightMsgPause int = 20
OpWeightSubmitCommitteeChangeProposal int = 20
)
2 changes: 2 additions & 0 deletions app/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/kava-labs/kava/x/cdp"
"github.com/kava-labs/kava/x/committee"
"github.com/kava-labs/kava/x/incentive"
"github.com/kava-labs/kava/x/issuance"
"github.com/kava-labs/kava/x/kavadist"
"github.com/kava-labs/kava/x/pricefeed"
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
Expand Down Expand Up @@ -84,6 +85,7 @@ func (tApp TestApp) GetBep3Keeper() bep3.Keeper { return tApp.bep3Keep
func (tApp TestApp) GetKavadistKeeper() kavadist.Keeper { return tApp.kavadistKeeper }
func (tApp TestApp) GetIncentiveKeeper() incentive.Keeper { return tApp.incentiveKeeper }
func (tApp TestApp) GetCommitteeKeeper() committee.Keeper { return tApp.committeeKeeper }
func (tApp TestApp) GetIssuanceKeeper() issuance.Keeper { return tApp.issuanceKeeper }

// This calls InitChain on the app using the default genesis state, overwitten with any passed in genesis states
func (tApp TestApp) InitializeFromGenesisStates(genesisStates ...GenesisState) TestApp {
Expand Down
17 changes: 17 additions & 0 deletions x/issuance/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package issuance

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/issuance/keeper"
)

// BeginBlocker iterates over each asset and seizes coins from blocked addresses by returning them to the asset owner
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
params := k.GetParams(ctx)
for _, asset := range params.Assets {
err := k.SeizeCoinsFromBlockedAddresses(ctx, asset.Denom)
if err != nil {
panic(err)
}
}
}
81 changes: 81 additions & 0 deletions x/issuance/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package issuance

import (
"github.com/kava-labs/kava/x/issuance/keeper"
"github.com/kava-labs/kava/x/issuance/types"
)

// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/kava-labs/kava/x/issuance/keeper
// ALIASGEN: github.com/kava-labs/kava/x/issuance/types

const (
EventTypeIssue = types.EventTypeIssue
EventTypeRedeem = types.EventTypeRedeem
EventTypeBlock = types.EventTypeBlock
EventTypeUnblock = types.EventTypeUnblock
EventTypePause = types.EventTypePause
EventTypeSeize = types.EventTypeSeize
AttributeValueCategory = types.AttributeValueCategory
AttributeKeyDenom = types.AttributeKeyDenom
AttributeKeyIssueAmount = types.AttributeKeyIssueAmount
AttributeKeyRedeemAmount = types.AttributeKeyRedeemAmount
AttributeKeyBlock = types.AttributeKeyBlock
AttributeKeyUnblock = types.AttributeKeyUnblock
AttributeKeyAddress = types.AttributeKeyAddress
AttributeKeyPauseStatus = types.AttributeKeyPauseStatus
ModuleName = types.ModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
DefaultParamspace = types.DefaultParamspace
QuerierRoute = types.QuerierRoute
QueryGetParams = types.QueryGetParams
QueryGetAsset = types.QueryGetAsset
)

var (
// functions aliases
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
RegisterCodec = types.RegisterCodec
NewGenesisState = types.NewGenesisState
DefaultGenesisState = types.DefaultGenesisState
NewMsgIssueTokens = types.NewMsgIssueTokens
NewMsgRedeemTokens = types.NewMsgRedeemTokens
NewMsgBlockAddress = types.NewMsgBlockAddress
NewMsgUnblockAddress = types.NewMsgUnblockAddress
NewMsgSetPauseStatus = types.NewMsgSetPauseStatus
NewParams = types.NewParams
DefaultParams = types.DefaultParams
ParamKeyTable = types.ParamKeyTable
NewAsset = types.NewAsset

// variable aliases
ModuleCdc = types.ModuleCdc
ErrAssetNotFound = types.ErrAssetNotFound
ErrNotAuthorized = types.ErrNotAuthorized
ErrAssetPaused = types.ErrAssetPaused
ErrAccountBlocked = types.ErrAccountBlocked
ErrAccountAlreadyBlocked = types.ErrAccountAlreadyBlocked
ErrAccountAlreadyUnblocked = types.ErrAccountAlreadyUnblocked
ErrIssueToModuleAccount = types.ErrIssueToModuleAccount
KeyAssets = types.KeyAssets
DefaultAssets = types.DefaultAssets
ModuleAccountName = types.ModuleAccountName
)

type (
Keeper = keeper.Keeper
GenesisState = types.GenesisState
MsgIssueTokens = types.MsgIssueTokens
MsgRedeemTokens = types.MsgRedeemTokens
MsgBlockAddress = types.MsgBlockAddress
MsgUnblockAddress = types.MsgUnblockAddress
MsgSetPauseStatus = types.MsgSetPauseStatus
Params = types.Params
Asset = types.Asset
Assets = types.Assets
QueryAssetParams = types.QueryAssetParams
)
55 changes: 55 additions & 0 deletions x/issuance/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"

"github.com/kava-labs/kava/x/issuance/types"
)

// GetQueryCmd returns the cli query commands for the issuance module
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
issuanceQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
}

issuanceQueryCmd.AddCommand(flags.GetCommands(
queryParamsCmd(queryRoute, cdc),
)...)

return issuanceQueryCmd

}

func queryParamsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "params",
Short: fmt.Sprintf("get the %s module parameters", types.ModuleName),
Long: "Get the current global issuance module parameters.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

// Query
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetParams)
res, height, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}
cliCtx = cliCtx.WithHeight(height)

// Decode and print results
var params types.Params
if err := cdc.UnmarshalJSON(res, &params); err != nil {
return fmt.Errorf("failed to unmarshal params: %w", err)
}
return cliCtx.PrintOutput(params)
},
}
}
Loading