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

feat(mint): add DevelopmentFund to block rewards #839

Merged
merged 6 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ genesis:
params:
mint_denom: "uspn"
distribution_proportions:
staking: "0.400000000000000000"
staking: "0.300000000000000000"
incentives: "0.400000000000000000"
community_pool: "0.200000000000000000"
development_fund: "0.200000000000000000"
community_pool: "0.100000000000000000"
development_fund_recipients:
- address: "spn1ezptsm3npn54qx9vvpah4nymre59ykr9exx2ul" # alice
weight: "0.400000000000000000"
- address: "spn1aqn8ynvr3jmq67879qulzrwhchq5dtrvtx0nhe" # bob
weight: "0.300000000000000000"
- address: "spn1pkdk6m2nh77nlaep84cylmkhjder3arey7rll5" # carol
weight: "0.300000000000000000"
launch:
params:
revertDelay: "5"
Expand All @@ -73,8 +81,8 @@ genesis:
fundraising:
params:
auction_creation_fee:
- "amount": "100"
"denom": "uspn"
- amount: "100"
denom: "uspn"
monitoringp:
params:
lastBlockHeight: "1"
Expand Down
21 changes: 20 additions & 1 deletion proto/mint/mint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ message Minter {
];
}

message WeightedAddress {
string address = 1;
string weight = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message DistributionProportions {
// staking defines the proportion of the minted minted_denom that is to be
// allocated as staking rewards.
Expand All @@ -30,9 +38,15 @@ message DistributionProportions {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// development_fund defines the proportion of the minted minted_denom that is
// to be allocated for development funding.
string development_fund = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// community_pool defines the proportion of the minted minted_denom that is
// to be allocated to the community pool.
string community_pool = 3 [
string community_pool = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
Expand Down Expand Up @@ -69,4 +83,9 @@ message Params {
// distribution_proportions defines the proportion of the minted denom
DistributionProportions distribution_proportions = 7
[ (gogoproto.nullable) = false ];

// address to receive developer rewards
repeated WeightedAddress development_fund_recipients = 8 [
(gogoproto.nullable) = false
];
}
29 changes: 28 additions & 1 deletion x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
spnerrors "github.com/tendermint/spn/pkg/errors"
"github.com/tendermint/tendermint/libs/log"

"github.com/tendermint/spn/x/mint/types"
Expand Down Expand Up @@ -140,8 +141,34 @@ func (k Keeper) DistributeMintedCoins(ctx sdk.Context, mintedCoin sdk.Coin) erro
// return err
// }

devFundCoin := k.GetProportions(ctx, mintedCoin, proportions.DevelopmentFund)
devFundCoins := sdk.NewCoins(devFundCoin)
if len(params.DevelopmentFundRecipients) == 0 {
// fund community pool when rewards address is empty
if err = k.distrKeeper.FundCommunityPool(
ctx,
devFundCoins,
k.accountKeeper.GetModuleAddress(types.ModuleName),
); err != nil {
return err
}
} else {
// allocate developer rewards to developer addresses by weight
for _, w := range params.DevelopmentFundRecipients {
devFundPortionCoins := sdk.NewCoins(k.GetProportions(ctx, devFundCoin, w.Weight))
devAddr, err := sdk.AccAddressFromBech32(w.Address)
if err != nil {
giunatale marked this conversation as resolved.
Show resolved Hide resolved
return spnerrors.Critical(err.Error())
}
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, devAddr, devFundPortionCoins)
if err != nil {
return err
}
}
}

// subtract from original provision to ensure no coins left over after the allocations
communityPoolCoins := sdk.NewCoins(mintedCoin).Sub(stakingRewardsCoins).Sub(incentivesCoins)
communityPoolCoins := sdk.NewCoins(mintedCoin).Sub(stakingRewardsCoins).Sub(incentivesCoins).Sub(devFundCoins)
err = k.distrKeeper.FundCommunityPool(ctx, communityPoolCoins, k.accountKeeper.GetModuleAddress(types.ModuleName))
if err != nil {
return err
Expand Down
60 changes: 49 additions & 11 deletions x/mint/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

"github.com/tendermint/spn/testutil/sample"
"github.com/tendermint/spn/x/mint/types"
)

// Simulation parameter constants
const (
Inflation = "inflation"
InflationRateChange = "inflation_rate_change"
InflationMax = "inflation_max"
InflationMin = "inflation_min"
GoalBonded = "goal_bonded"
DistributionProportions = "distribution_proportions"
Inflation = "inflation"
InflationRateChange = "inflation_rate_change"
InflationMax = "inflation_max"
InflationMin = "inflation_min"
GoalBonded = "goal_bonded"
DistributionProportions = "distribution_proportions"
DevelopmentFundRecipients = "development_fund_recipients"
)

// GenInflation randomized Inflation
Expand Down Expand Up @@ -53,15 +56,44 @@ func GenDistributionProportions(r *rand.Rand) types.DistributionProportions {
staking := r.Int63n(99)
left := int64(100) - staking
incentives := r.Int63n(left)
communityPool := left - incentives
left -= incentives
devs := r.Int63n(left)
communityPool := left - devs
giunatale marked this conversation as resolved.
Show resolved Hide resolved

return types.DistributionProportions{
Staking: sdk.NewDecWithPrec(staking, 2),
Incentives: sdk.NewDecWithPrec(incentives, 2),
CommunityPool: sdk.NewDecWithPrec(communityPool, 2),
Staking: sdk.NewDecWithPrec(staking, 2),
Incentives: sdk.NewDecWithPrec(incentives, 2),
DevelopmentFund: sdk.NewDecWithPrec(devs, 2),
CommunityPool: sdk.NewDecWithPrec(communityPool, 2),
}
}

func GenDevelopmentFundRecipients(r *rand.Rand) []types.WeightedAddress {
var (
addrs = make([]types.WeightedAddress, 0)
numAddrs = r.Intn(51)
remainWeight = sdk.NewDec(1)
maxRandWeight = sdk.NewDecWithPrec(15, 3)
minRandWeight = sdk.NewDecWithPrec(5, 3)
)
for i := 0; i < numAddrs; i++ {
// each address except the last can have a max of 2% weight and a min of 0.5%
weight := simtypes.RandomDecAmount(r, maxRandWeight).Add(minRandWeight)
if i == numAddrs-1 {
// use residual weight if last address
weight = remainWeight
} else {
remainWeight = remainWeight.Sub(weight)
}
wa := types.WeightedAddress{
Address: sample.Address(r),
Weight: weight,
}
addrs = append(addrs, wa)
}
return addrs
}

// RandomizedGenState generates a random GenesisState for mint
func RandomizedGenState(simState *module.SimulationState) {
// minter
Expand Down Expand Up @@ -102,9 +134,15 @@ func RandomizedGenState(simState *module.SimulationState) {
func(r *rand.Rand) { distributionProportions = GenDistributionProportions(r) },
)

var developmentFundRecipients []types.WeightedAddress
simState.AppParams.GetOrGenerate(
simState.Cdc, DevelopmentFundRecipients, &developmentFundRecipients, simState.Rand,
func(r *rand.Rand) { developmentFundRecipients = GenDevelopmentFundRecipients(r) },
)

mintDenom := sdk.DefaultBondDenom
blocksPerYear := uint64(60 * 60 * 8766 / 5)
params := types.NewParams(mintDenom, inflationRateChange, inflationMax, inflationMin, goalBonded, blocksPerYear, distributionProportions)
params := types.NewParams(mintDenom, inflationRateChange, inflationMax, inflationMin, goalBonded, blocksPerYear, distributionProportions, developmentFundRecipients)

mintGenesis := types.NewGenesisState(types.InitialMinter(inflation), params)

Expand Down
Loading