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: finish incentive module #1952

Merged
merged 99 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
1993bee
exponent fix
toteki Mar 22, 2023
5fd04dc
store reward accumulator exponent
toteki Mar 23, 2023
0954eb9
spec abstract
toteki Mar 23, 2023
7427012
rename field
toteki Mar 24, 2023
993a249
initial app wiring
toteki Mar 27, 2023
9e3f62e
Merge branch 'main' into adam/incentive-finish
toteki Mar 27, 2023
c5e48f8
Merge branch 'main' into adam/incentive-finish
toteki Mar 27, 2023
3423b1a
comment out incomplete invariant
toteki Mar 27, 2023
402511a
Merge branch 'main' into adam/incentive-finish
toteki Mar 27, 2023
5355a17
implement govtypes.Content
toteki Mar 28, 2023
a232cad
bug todo
toteki Mar 28, 2023
f576233
package umee.incentive.v1
toteki Mar 28, 2023
54595f1
add message name option to tx.proto
toteki Mar 28, 2023
0c4dc1a
fix bug
toteki Mar 28, 2023
a4c59a4
++
toteki Mar 28, 2023
30ac663
Merge branch 'main' into adam/incentive-finish
toteki Mar 29, 2023
8bd485c
make proto-all
toteki Mar 29, 2023
b4968e5
proto: remove unbonding tiers
toteki Mar 30, 2023
172e9d0
remove unbonding tiers from code
toteki Mar 30, 2023
04c2eb6
--
toteki Mar 30, 2023
389cebe
allow unbonding duration zero
toteki Mar 30, 2023
cdce189
skip unbonding creation when duration is zero
toteki Mar 30, 2023
ebbdf70
update queries; unbonding time decrease affects ongoing unbondings
toteki Mar 30, 2023
85e53d3
commit everything, everywhere, all at once
toteki Apr 3, 2023
32b0bc2
Merge branch 'main' into adam/incentive-finish
toteki Apr 3, 2023
65460fa
fix tests without changing module init order
toteki Apr 4, 2023
e1e1bdc
userMaxWithdraw now respects bonded collateral
toteki Apr 4, 2023
cd00d60
mock leverage keeper tokens
toteki Apr 6, 2023
9aea24c
remove circular keeper reference and refactor hooks
toteki Apr 6, 2023
e6899dc
msg bond tests
toteki Apr 7, 2023
dbb52d4
lint
toteki Apr 7, 2023
1d5a412
md lint
toteki Apr 7, 2023
502209f
Merge branch 'main' into adam/incentive-finish
toteki Apr 7, 2023
dcfdb50
tests
toteki Apr 11, 2023
5ac90b6
test max unbondings
toteki Apr 11, 2023
682ab8d
unbonding completion test
toteki Apr 11, 2023
abdf478
++
toteki Apr 11, 2023
f7ad403
implement emergency unbond logic
toteki Apr 12, 2023
3058ecb
remove ErrNotImplemented
toteki Apr 12, 2023
07b6afa
proto field renames
toteki Apr 12, 2023
b209659
todon't
toteki Apr 12, 2023
874a741
extra incentiveprogram validate
toteki Apr 12, 2023
685d6f3
more validation
toteki Apr 12, 2023
af1eed3
suggestion++
toteki Apr 13, 2023
2ce3e0d
suggestion++
toteki Apr 13, 2023
2e22312
suggestion++
toteki Apr 13, 2023
d04b066
suggestion++
toteki Apr 13, 2023
e419b28
do not override heeper when setting hooks
toteki Apr 13, 2023
931f94d
implement proto change suggestions
toteki Apr 13, 2023
b0b7606
suggestion++
toteki Apr 13, 2023
e00317b
suggestion++
toteki Apr 14, 2023
f4cf37e
suggestion++
toteki Apr 14, 2023
b1a1e70
suggestion++
toteki Apr 14, 2023
1fc0159
suggested whitespace (app)
toteki Apr 14, 2023
c2f713c
implement all util/keys changes
toteki Apr 14, 2023
f208feb
Merge branch 'main' into adam/incentive-finish
toteki Apr 14, 2023
3570e5e
fix merge
toteki Apr 14, 2023
5ba2b57
suggestion++
toteki Apr 14, 2023
7c749df
suggestion++
toteki Apr 14, 2023
13bae8a
validate functions for genesis subtypes
toteki Apr 14, 2023
fe586ba
genesis test stub
toteki Apr 14, 2023
c6822ff
add gov create programs test
toteki Apr 16, 2023
9b79844
emergency unbond test
toteki Apr 17, 2023
4ecdb41
msg sponsor tests
toteki Apr 17, 2023
dbeeb57
Merge branch 'main' into adam/incentive-finish
toteki Apr 17, 2023
6d105a2
early return in updateRewards
robert-zaremba Apr 19, 2023
4a8004c
suggestion++
toteki Apr 19, 2023
da5b4b8
cosmetic update in updateRewards
robert-zaremba Apr 19, 2023
637f7c6
Merge branch 'main' into adam/incentive-finish
toteki Apr 19, 2023
739fc10
suggestion++
toteki Apr 19, 2023
f1a2cd5
partial scenario test
toteki Apr 20, 2023
b945573
refactor all incentive tests to unit tests
toteki Apr 22, 2023
c433515
cleanup
toteki Apr 22, 2023
b0d86cb
lint
toteki Apr 22, 2023
8d198e0
cleanup incentive program add/modify/delete functions
toteki Apr 23, 2023
6878c11
fixed bug
toteki Apr 23, 2023
92c8161
finishUnbondings -> cleanupUnbondings
toteki Apr 23, 2023
3f1d98e
break loop early
toteki Apr 23, 2023
cea06d3
remove unnecessary gov.Content
toteki Apr 23, 2023
aa83e9a
Merge branch 'main' into adam/incentive-finish
toteki Apr 23, 2023
9860511
comment--
toteki Apr 23, 2023
cb4c2aa
remove proto getters-all
toteki Apr 23, 2023
49fc646
remove proto messagename-all
toteki Apr 23, 2023
9bae74a
rename to ForceUnbondTo
toteki Apr 23, 2023
9017966
initialize exponent on program create (gov)
toteki Apr 24, 2023
d4534ba
add v4.4 migrator
toteki Apr 24, 2023
991f02a
allow setting max unbondings to unlimited
toteki Apr 24, 2023
bad4a29
replace panic with err in iterators
toteki Apr 24, 2023
4096b96
Merge branch 'main' into adam/incentive-finish
toteki Apr 24, 2023
1aed4b8
remove communtiy fund param - use distribution module account
toteki Apr 24, 2023
d5a567d
proto doc max unbondings
toteki Apr 25, 2023
96bbc1e
emergency unbond CLI was missing
toteki Apr 25, 2023
1a2b859
typo
toteki Apr 25, 2023
b3ce29a
comment
toteki Apr 25, 2023
c71635a
max unbondings default to 10
toteki Apr 25, 2023
a18eff9
comment--
toteki Apr 25, 2023
228cb0c
remove redundant empty string check
toteki Apr 25, 2023
28feba5
refactor functions surrounding reduceBondTo
toteki Apr 25, 2023
06b4a55
add current rates query for frontend
toteki Apr 25, 2023
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
22 changes: 20 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ import (
appparams "github.com/umee-network/umee/v4/app/params"
"github.com/umee-network/umee/v4/swagger"
"github.com/umee-network/umee/v4/util/genmap"
"github.com/umee-network/umee/v4/x/incentive"
incentivekeeper "github.com/umee-network/umee/v4/x/incentive/keeper"
incentivemodule "github.com/umee-network/umee/v4/x/incentive/module"
"github.com/umee-network/umee/v4/x/leverage"
leveragekeeper "github.com/umee-network/umee/v4/x/leverage/keeper"
leveragetypes "github.com/umee-network/umee/v4/x/leverage/types"
Expand Down Expand Up @@ -175,6 +178,7 @@ func init() {
ibctransfer.AppModuleBasic{},
gravity.AppModuleBasic{},
leverage.AppModuleBasic{},
incentivemodule.AppModuleBasic{},
oracle.AppModuleBasic{},
bech32ibc.AppModuleBasic{},
uibcmodule.AppModuleBasic{},
Expand All @@ -198,6 +202,7 @@ func init() {
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
leveragetypes.ModuleName: {authtypes.Minter, authtypes.Burner},
incentive.ModuleName: nil,
oracletypes.ModuleName: nil,
uibc.ModuleName: nil,
}
Expand Down Expand Up @@ -247,6 +252,7 @@ type UmeeApp struct {
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
GravityKeeper gravitykeeper.Keeper
LeverageKeeper leveragekeeper.Keeper
IncentiveKeeper incentivekeeper.Keeper
OracleKeeper oraclekeeper.Keeper
bech32IbcKeeper bech32ibckeeper.Keeper
UIbcQuotaKeeper uibcquotakeeper.Keeper
Expand Down Expand Up @@ -310,8 +316,8 @@ func New(
evidencetypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey,
ibchost.StoreKey, ibctransfertypes.StoreKey, gravitytypes.StoreKey,
leveragetypes.StoreKey, oracletypes.StoreKey, bech32ibctypes.StoreKey,
uibc.StoreKey,
leveragetypes.StoreKey, incentive.StoreKey, oracletypes.StoreKey,
bech32ibctypes.StoreKey, uibc.StoreKey,
}
if Experimental {
storeKeys = append(storeKeys, wasm.StoreKey)
Expand Down Expand Up @@ -454,6 +460,12 @@ func New(
app.OracleKeeper.Hooks(),
),
)
app.IncentiveKeeper = incentivekeeper.NewKeeper(
appCodec,
keys[incentive.StoreKey],
app.BankKeeper,
app.LeverageKeeper,
)

app.GravityKeeper = gravitykeeper.NewKeeper(
keys[gravitytypes.StoreKey],
Expand Down Expand Up @@ -626,6 +638,7 @@ func New(
ibctransfer.NewAppModule(ibcTransferKeeper),
gravity.NewAppModule(app.GravityKeeper, app.BankKeeper),
leverage.NewAppModule(appCodec, app.LeverageKeeper, app.AccountKeeper, app.BankKeeper),
incentivemodule.NewAppModule(appCodec, app.IncentiveKeeper, app.BankKeeper, app.LeverageKeeper),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
bech32ibc.NewAppModule(appCodec, app.bech32IbcKeeper),
uibcmodule.NewAppModule(appCodec, app.UIbcQuotaKeeper),
Expand Down Expand Up @@ -655,6 +668,7 @@ func New(
paramstypes.ModuleName, vestingtypes.ModuleName,
// icatypes.ModuleName, ibcfeetypes.ModuleName,
leveragetypes.ModuleName,
incentive.ModuleName,
oracletypes.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
Expand All @@ -673,6 +687,7 @@ func New(
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
// icatypes.ModuleName,
leveragetypes.ModuleName,
incentive.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
uibc.ModuleName,
Expand All @@ -694,6 +709,7 @@ func New(

oracletypes.ModuleName,
leveragetypes.ModuleName,
incentive.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
uibc.ModuleName,
Expand All @@ -709,6 +725,7 @@ func New(

oracletypes.ModuleName,
leveragetypes.ModuleName,
incentive.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
uibc.ModuleName,
Expand Down Expand Up @@ -748,6 +765,7 @@ func New(
[]string{stakingtypes.ModuleName, authtypes.ModuleName, oracletypes.ModuleName},
)
// TODO: Ensure x/leverage implements simulator and add it here:
// TODO: same for incentive
toteki marked this conversation as resolved.
Show resolved Hide resolved
simTestModules := genmap.Pick(simStateModules, []string{oracletypes.ModuleName})

app.StateSimulationManager = module.NewSimulationManagerFromAppModules(simStateModules, overrideModules)
Expand Down
23 changes: 13 additions & 10 deletions proto/umee/incentive/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,28 @@ message Bond {
// RewardAccumulator for a tier and the last value at which the user updated bonds or claimed
// tokens. Their pending rewards increase by only the rewards accrued in that time period.
message RewardTracker {
string account = 1;
uint32 tier = 2;
string denom = 3;
repeated cosmos.base.v1beta1.DecCoin reward_tracker = 4 [
string account = 1;
uint32 tier = 2;
string denom = 3;
repeated cosmos.base.v1beta1.DecCoin rewards = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"
];
}

// RewardAccumulator is a global reward tracking struct that indicates the amount
// of rewards that a single unit of denom would have accumulated if it was bonded
// at a given tier since genesis.
// of rewards that a reference amount of a bonded uToken denom would have accumulated
// if it was bonded at a given tier since genesis. To prevent rounding issues, the
// reference amount is 10^exponent of the uToken's smallest possible amount, generally
// matching the exponent of the associated base token registered with the leverage module.
message RewardAccumulator {
uint32 tier = 1;
string denom = 2;
repeated cosmos.base.v1beta1.DecCoin reward_tracker = 3 [
uint32 tier = 1;
string denom = 2;
repeated cosmos.base.v1beta1.DecCoin rewards = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"
];
uint32 exponent = 4;
}

// Unbonding is a structure that tracks an in-progress token unbonding.
Expand All @@ -76,4 +79,4 @@ message AccountUnbondings {
string denom = 2;
uint32 tier = 3;
repeated Unbonding unbondings = 4 [(gogoproto.nullable) = false];
}
}
9 changes: 9 additions & 0 deletions x/incentive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Incentive Module

## Abstract

This document specifies the `x/incentive` module of the Umee chain.

The incentive module allows users to `Bond` collateral `uTokens` from the `x/leverage` module, and governance to create and fund `Incentive Programs` which distribute rewards to users with bonded uTokens over time. Users can `Unbond` tokens over a period of time, after which they can be withdrawn. Unbonding time (and reward amounts) depend on which of the three `Unbonding Tiers` uTokens were bonded to.

The incentive module depends on the `x/leverage` module for information about users' bonded collateral, and also requires that the leverage module prevent bonded or currently unbonding collateral from being withdrawn. There are also a few more advanced interactions, such as instantly unbonding collateral when it is liquidated, and registering an `exponent` when a uToken denom is incentivized for the first time.
5 changes: 3 additions & 2 deletions x/incentive/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
ErrInsufficientCollateral = errors.Register(ModuleName, 404, "insufficient collateral to create bond")

// 5XX = Misc
ErrDecreaseNextProgramID = errors.Register(ModuleName, 500, "cannot decrease NextProgramID")
ErrDecreaseLastRewardTime = errors.Register(ModuleName, 501, "cannot decrease LastRewardTime")
ErrDecreaseNextProgramID = errors.Register(ModuleName, 500, "cannot decrease NextProgramID")
ErrDecreaseLastRewardTime = errors.Register(ModuleName, 501, "cannot decrease LastRewardTime")
ErrChangeAccumulatorExponent = errors.Register(ModuleName, 502, "cannot change RewardAccumulator.Exponent once set")
)
4 changes: 1 addition & 3 deletions x/incentive/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ type BankKeeper interface {

// LeverageKeeper defines the expected x/leverage keeper interface.
type LeverageKeeper interface {
GetCollateralAmount(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) sdk.Coin
IsAcceptedUToken(ctx sdk.Context, uTokenDenom string) bool
AssertNotBlacklisted(ctx sdk.Context, denom string) error
GetCollateral(ctx sdk.Context, borrowerAddr sdk.AccAddress, denom string) sdk.Coin
// TODO: hooks
}
25 changes: 13 additions & 12 deletions x/incentive/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ func NewGenesisState(
}
}

// DefaultGenesisState returns the default genesis state
func DefaultGenesisState() *GenesisState {
// DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
NextProgramId: 1,
LastRewardsTime: 0,
}
}

// ValidateGenesis checks a genesis state for basic issues
func ValidateGenesis(_ GenesisState) error {
// Validate checks a genesis state for basic issues
func (gs GenesisState) Validate() error {
// TODO #1749
return nil
}
Expand Down Expand Up @@ -101,19 +101,20 @@ func NewTotalBond(tier uint32, coin sdk.Coin) Bond {
// NewRewardTracker creates the RewardTracker struct used in GenesisState
func NewRewardTracker(addr, denom string, tier uint32, coins sdk.DecCoins) RewardTracker {
return RewardTracker{
Account: addr,
Denom: denom,
Tier: tier,
RewardTracker: coins,
Account: addr,
Denom: denom,
Tier: tier,
Rewards: coins,
}
}

// NewRewardAccumulator creates the RewardAccumulator struct used in GenesisState
func NewRewardAccumulator(denom string, tier uint32, coins sdk.DecCoins) RewardAccumulator {
func NewRewardAccumulator(denom string, tier, exponent uint32, coins sdk.DecCoins) RewardAccumulator {
return RewardAccumulator{
Denom: denom,
Tier: tier,
RewardTracker: coins,
Denom: denom,
Tier: tier,
Exponent: exponent,
Rewards: coins,
}
}

Expand Down
Loading