diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index d2a567fa4..3166a6cc2 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -11,9 +11,9 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" + distr "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/stake" - distr "github.com/cosmos/cosmos-sdk/x/stake" stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types" "github.com/spf13/pflag" diff --git a/x/distribution/alias.go b/x/distribution/alias.go new file mode 100644 index 000000000..a89375034 --- /dev/null +++ b/x/distribution/alias.go @@ -0,0 +1,74 @@ +// nolint +package stake + +import ( + "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + "github.com/cosmos/cosmos-sdk/x/distribution/querier" + "github.com/cosmos/cosmos-sdk/x/distribution/tags" + "github.com/cosmos/cosmos-sdk/x/distribution/types" +) + +type ( + Keeper = keeper.Keeper + DelegatorWithdrawInfo = types.DelegatorWithdrawInfo + DelegatorDistInfo = types.DelegatorDistInfo + ValidatorDistInfo = types.ValidatorDistInfo + TotalAccum = types.TotalAccum + FeePool = types.FeePool + + MsgSetWithdrawAddress = types.MsgSetWithdrawAddress + MsgWithdrawDelegatorRewardsAll = types.MsgWithdrawDelegatorRewardsAll + MsgWithdrawDelegationReward = types.MsgWithdrawDelegationReward + MsgWithdrawValidatorRewardsAll = types.MsgWithdrawValidatorRewardsAll + + GenesisState = types.GenesisState +) + +var ( + NewKeeper = keeper.NewKeeper + NewQuerier = querier.NewQuerier + + GetValidatorDistInfoKey = keeper.GetValidatorDistInfoKey + GetDelegationDistInfoKey = keeper.GetDelegationDistInfoKey + GetDelegationDistInfosKey = keeper.GetDelegationDistInfosKey + GetDelegatorWithdrawAddrKey = keeper.GetDelegatorWithdrawAddrKey + FeePoolKey = keeper.FeePoolKey + ValidatorDistInfoKey = keeper.ValidatorDistInfoKey + DelegatorDistInfoKey = keeper.DelegatorDistInfoKey + DelegatorWithdrawInfoKey = keeper.DelegatorWithdrawInfoKey + ProposerKey = keeper.ProposerKey + + InitialFeePool = types.InitialFeePool + + NewGenesisState = types.NewGenesisState + DefaultGenesisState = types.DefaultGenesisState + + RegisterCodec = types.RegisterCodec + + NewMsgSetWithdrawAddress = types.NewMsgSetWithdrawAddress + NewMsgWithdrawDelegatorRewardsAll = types.NewMsgWithdrawDelegatorRewardsAll + NewMsgWithdrawDelegationReward = types.NewMsgWithdrawDelegationReward + NewMsgWithdrawValidatorRewardsAll = types.NewMsgWithdrawValidatorRewardsAll +) + +const ( + DefaultCodespace = types.DefaultCodespace + CodeInvalidInput = types.CodeInvalidInput +) + +var ( + ErrNilDelegatorAddr = types.ErrNilDelegatorAddr + ErrNilWithdrawAddr = types.ErrNilWithdrawAddr + ErrNilValidatorAddr = types.ErrNilValidatorAddr +) + +var ( + ActionModifyWithdrawAddress = tags.ActionModifyWithdrawAddress + ActionWithdrawDelegatorRewardsAll = tags.ActionWithdrawDelegatorRewardsAll + ActionWithdrawDelegatorReward = tags.ActionWithdrawDelegatorReward + ActionWithdrawValidatorRewardsAll = tags.ActionWithdrawValidatorRewardsAll + + TagAction = tags.Action + TagValidator = tags.SrcValidator + TagDelegator = tags.Delegator +) diff --git a/x/distribution/genesis.go b/x/distribution/genesis.go index f377750f8..045c840ed 100644 --- a/x/distribution/genesis.go +++ b/x/distribution/genesis.go @@ -5,12 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/stake/types" ) -// InitGenesis sets the pool and parameters for the provided keeper and -// initializes the IntraTxCounter. For each validator in data, it sets that -// validator in the keeper along with manually setting the indexes. In -// addition, it also sets any delegations found in data. Finally, it updates -// the bonded validators. -// Returns final validator set after applying all declaration and delegations +// InitGenesis sets distribution information for genesis func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) { keeper.SetFeePool(ctx, data.FeePool) diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index 922d60989..d6e586b60 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -30,7 +30,7 @@ func (k Keeper) AllocateFees(ctx sdk.Context) { proposerDist.Pool = proposerDist.Pool.Add(proposerReward.Sub(commission)) // allocate community funding - communityTax := sdk.NewDecWithPrec(1, 2) // XXX TODO get from global params store + communityTax := k.GetCommunityTax(ctx) communityFunding := feesCollectedDec.Mul(communityTax) feePool := k.GetFeePool(ctx) feePool.CommunityFund = feePool.CommunityFund.Add(communityFunding) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 13c5a0b73..ff5ab62cc 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -5,6 +5,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/params" +) + +// nolint +const ( + ParamStoreKeyCommunityTax = "distr/community-tax" ) // keeper of the stake store @@ -12,6 +18,7 @@ type Keeper struct { storeKey sdk.StoreKey storeTKey sdk.StoreKey cdc *wire.Codec + ps params.Setter coinKeeper types.CoinKeeper stakeKeeper types.StakeKeeper @@ -19,7 +26,7 @@ type Keeper struct { codespace sdk.CodespaceType } -func NewKeeper(cdc *wire.Codec, key, tkey sdk.StoreKey, ck types.CoinKeeper, +func NewKeeper(cdc *wire.Codec, key, tkey sdk.StoreKey, ps params.Setter, ck types.CoinKeeper, sk types.StakeKeeper, codespace sdk.CodespaceType) Keeper { keeper := Keeper{ @@ -75,3 +82,18 @@ func (k Keeper) SetProposerConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) { b := k.cdc.MustMarshalBinary(consAddr) store.Set(ProposerKey, b) } + +//______________________________________________________________________ + +// Returns the current Deposit Procedure from the global param store +// nolint: errcheck +func (k Keeper) GetCommunityTax(ctx sdk.Context) sdk.Dec { + var communityTax sdk.Dec + keeper.ps.Get(ctx, ParamStoreKeyCommunityTax, &communityTax) + return communityTax +} + +// nolint: errcheck +func (k Keeper) setCommunityTax(ctx sdk.Context, communityTax sdk.Dec) { + keeper.ps.Set(ctx, ParamStoreKeyCommunityTax, &communityTax) +} diff --git a/x/distribution/types/errors.go b/x/distribution/types/errors.go new file mode 100644 index 000000000..57a3dd73e --- /dev/null +++ b/x/distribution/types/errors.go @@ -0,0 +1,23 @@ +// nolint +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type CodeType = sdk.CodeType + +const ( + DefaultCodespace sdk.CodespaceType = 6 + CodeInvalidInput CodeType = 103 +) + +func ErrNilDelegatorAddr(codespace sdk.CodespaceType) sdk.Error { + return sdk.NewError(codespace, CodeInvalidInput, "delegator address is nil") +} +func ErrNilWithdrawAddr(codespace sdk.CodespaceType) sdk.Error { + return sdk.NewError(codespace, CodeInvalidInput, "withdraw address is nil") +} +func ErrNilValidatorAddr(codespace sdk.CodespaceType) sdk.Error { + return sdk.NewError(codespace, CodeInvalidInput, "validator address is nil") +}