Skip to content

Commit

Permalink
Feat/incentive gas distribute (#72)
Browse files Browse the repository at this point in the history
* add: scaffold incentive

* add: declare incentive params -LP &Stake

* add: implement hook interface functions in incentive module

* add: implement staking hook interface functions in incentive module

* add: add commitmentKeeper as incentive newkeeper param, declare keeper functions for staking hooks

* add: calls appropriate keeper functions ffrom hook functions

* fix: add one more param in calling newkeeper of testutil-incentive.go

* fix: remove exception handling for checking block height in hook functions in order to be succeed in unit test

* feat: add commitment hook and integrated into incentive module

* feat: calculated eden & eden boost uncomitted token amount

* fix: add parms config for incentive module

* fix: refactoring proto define of incentive param

* fix: remove wrongly merged code - double incentive keeper initiate

* fix: rebuild protobuf

* fix: correct data type of incentive params in config.yml and add an exception handling in staking hook ignore 0 block height

* Commitment Module Denom Checks (#55)

* check denom for commit enabled

* commitEnabled config

* withdraw check

* eden-boost assetprofile entry

* fix assetprofile enty decimals

* fix: addcurrent epoch in incentive param and refactoring code baseaccording to the comments

* fix: update getproperincentive param function and handle current epoch number

* fix: add eden boost APR and use it in eden boost calculation

* fix: change function to calculate delegation amount per delegator

* feat: add a map to record elys staker and delegators

* feat: add a data map to record elys standard staking

* feat: calculate commission to validator and give it

* feat: update the corresponding commistment to give each validator commissions

* fix: get rid of manual map for recording elys stake info in incentive module

* fix: get rid of manual map to record elys stake, currently havng issue with loading params

* feat: add protos from distribution module

* feat: add query for getting validator outstanding rewards

* feat: add query validator commission

* feat: add query for getting validator slashes

* feat: add query for getting delegation rewards

* feat: dd delegation total rewards

* feat: add a query for getting validators of a delegator

* feat: add community pool query

* feat: add query for getting delegator withdraw address

* feat: add a tx to set withdraw address in incentive module

* feat: add a tx to withdaraw validator commission

* feat: add a tx for withdrawing delegator reward

* feat: finished toten allocation

* feat: finish implementation of queryies and txs

* feat: handle staking hook

* feat: add place holder for converting Elys to USDC

* fix: remove referene to standard distribution module and fix export.go with distribution keeper

* feat: fix genesis paraams of incentive module in config.yml

* fix: update initi genesis and export genesis functions

* fix: fix issue with incentive module genesis initialization and unit testing

* fix: update incentive param initialization to fix unit testing issue

* fix: 🐛 duplicate maccperms

---------

Co-authored-by: Austin Haines <[email protected]>
Co-authored-by: Cosmic Vagabond <[email protected]>
  • Loading branch information
3 people authored May 9, 2023
1 parent 3d8f063 commit 1245e69
Show file tree
Hide file tree
Showing 58 changed files with 15,400 additions and 489 deletions.
41 changes: 10 additions & 31 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/evidence"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
Expand Down Expand Up @@ -151,7 +147,7 @@ func getGovProposalHandlers() []govclient.ProposalHandler {

govProposalHandlers = append(govProposalHandlers,
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
// distrclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
Expand All @@ -177,7 +173,6 @@ var (
capability.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(getGovProposalHandlers()),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand All @@ -204,16 +199,15 @@ var (
// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
icatypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
commitmentmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
incentivemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
burnermoduletypes.ModuleName: {authtypes.Burner},
incentivemoduletypes.ModuleName: nil,
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down Expand Up @@ -257,7 +251,6 @@ type ElysApp struct {
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
Expand Down Expand Up @@ -329,7 +322,7 @@ func NewElysApp(

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, authz.ModuleName, banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey,
minttypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey,
paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey,
ibctransfertypes.StoreKey, icahosttypes.StoreKey, capabilitytypes.StoreKey, group.StoreKey,
icacontrollertypes.StoreKey,
Expand Down Expand Up @@ -424,16 +417,6 @@ func NewElysApp(
authtypes.FeeCollectorName,
)

app.DistrKeeper = distrkeeper.NewKeeper(
appCodec,
keys[distrtypes.StoreKey],
app.GetSubspace(distrtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
&app.StakingKeeper,
authtypes.FeeCollectorName,
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
keys[slashingtypes.StoreKey],
Expand Down Expand Up @@ -551,7 +534,7 @@ func NewElysApp(
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
// AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(oracletypes.RouterKey, oraclemodule.NewAssetInfoProposalHandler(&app.OracleKeeper))
Expand Down Expand Up @@ -595,6 +578,9 @@ func NewElysApp(
app.GetSubspace(incentivemoduletypes.ModuleName),
commitmentKeeper,
app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
)
incentiveModule := incentivemodule.NewAppModule(appCodec, app.IncentiveKeeper)

Expand Down Expand Up @@ -661,7 +647,6 @@ func NewElysApp(
app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
// insert staking hooks receivers here
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.IncentiveKeeper.StakingHooks(),
),
Expand Down Expand Up @@ -709,7 +694,6 @@ func NewElysApp(
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, minttypes.DefaultInflationCalculationFn),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
Expand Down Expand Up @@ -739,7 +723,7 @@ func NewElysApp(
// Note: epochs' begin should be "real" start of epochs, we keep epochs beginblock at the beginning
epochsmoduletypes.ModuleName,
minttypes.ModuleName,
distrtypes.ModuleName,
incentivemoduletypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
Expand All @@ -761,7 +745,6 @@ func NewElysApp(
oracletypes.ModuleName,
commitmentmoduletypes.ModuleName,
tokenomicsmoduletypes.ModuleName,
incentivemoduletypes.ModuleName,
burnermoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)
Expand All @@ -778,7 +761,7 @@ func NewElysApp(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
incentivemoduletypes.ModuleName,
slashingtypes.ModuleName,
minttypes.ModuleName,
genutiltypes.ModuleName,
Expand All @@ -794,7 +777,6 @@ func NewElysApp(
oracletypes.ModuleName,
commitmentmoduletypes.ModuleName,
tokenomicsmoduletypes.ModuleName,
incentivemoduletypes.ModuleName,
burnermoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)
Expand All @@ -808,7 +790,7 @@ func NewElysApp(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
incentivemoduletypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
Expand All @@ -831,7 +813,6 @@ func NewElysApp(
oracletypes.ModuleName,
commitmentmoduletypes.ModuleName,
tokenomicsmoduletypes.ModuleName,
incentivemoduletypes.ModuleName,
burnermoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)
Expand All @@ -855,7 +836,6 @@ func NewElysApp(
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, minttypes.DefaultInflationCalculationFn),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
params.NewAppModule(app.ParamsKeeper),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -1068,7 +1048,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
Expand Down
20 changes: 10 additions & 10 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (app *ElysApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
_, err := app.IncentiveKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
if err != nil {
panic(err)
}
Expand All @@ -84,17 +84,17 @@ func (app *ElysApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
for _, delegation := range dels {
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
_, err := app.IncentiveKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
if err != nil {
panic(err)
}
}

// clear validator slash events
app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)
app.IncentiveKeeper.DeleteAllValidatorSlashEvents(ctx)

// clear validator historical rewards
app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
app.IncentiveKeeper.DeleteAllValidatorHistoricalRewards(ctx)

// set context height to zero
height := ctx.BlockHeight()
Expand All @@ -103,12 +103,12 @@ func (app *ElysApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
// reinitialize all validators
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.DistrKeeper.GetFeePool(ctx)
scraps := app.IncentiveKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.IncentiveKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)
app.IncentiveKeeper.SetFeePool(ctx, feePool)

err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
err := app.IncentiveKeeper.StakingHooks().AfterValidatorCreated(ctx, val.GetOperator())
if err != nil {
panic(err)
}
Expand All @@ -117,11 +117,11 @@ func (app *ElysApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [

// reinitialize all delegations
for _, del := range dels {
err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
err := app.IncentiveKeeper.StakingHooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
if err != nil {
panic(err)
}
err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
err = app.IncentiveKeeper.StakingHooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
if err != nil {
panic(err)
}
Expand Down
6 changes: 6 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ genesis:
num_epochs: "365"
current_epoch: "0"
eden_boost_apr: "100"
community_tax: "0.02"
withdraw_addr_enabled: true
fee_pool:
community_pool:
- amount: "0"
denom: uelys
tokenomics:
airdropList:
- intent: AtomStakers
Expand Down
Loading

0 comments on commit 1245e69

Please sign in to comment.