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 all 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
34 changes: 25 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,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 @@ -186,6 +189,7 @@ func init() {
// ibcfee.AppModuleBasic{},
gravity.AppModuleBasic{},
leverage.AppModuleBasic{},
incentivemodule.AppModuleBasic{},
oracle.AppModuleBasic{},
bech32ibc.AppModuleBasic{},
uibcmodule.AppModuleBasic{},
Expand All @@ -210,6 +214,7 @@ func init() {
icatypes.ModuleName: nil,
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 @@ -260,6 +265,7 @@ type UmeeApp struct {
ICAHostKeeper icahostkeeper.Keeper
GravityKeeper gravitykeeper.Keeper
LeverageKeeper leveragekeeper.Keeper
IncentiveKeeper incentivekeeper.Keeper
OracleKeeper oraclekeeper.Keeper
bech32IbcKeeper bech32ibckeeper.Keeper
UIbcQuotaKeeper uibcquotakeeper.Keeper
Expand Down Expand Up @@ -324,8 +330,8 @@ func New(
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey,
ibchost.StoreKey, ibctransfertypes.StoreKey, icahosttypes.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 @@ -466,11 +472,14 @@ func New(
app.OracleKeeper,
cast.ToBool(appOpts.Get(leveragetypes.FlagEnableLiquidatorQuery)),
)
app.LeverageKeeper = *app.LeverageKeeper.SetHooks(
leveragetypes.NewMultiHooks(
app.OracleKeeper.Hooks(),
),
app.IncentiveKeeper = incentivekeeper.NewKeeper(
appCodec,
keys[incentive.StoreKey],
app.BankKeeper,
app.LeverageKeeper,
)
app.LeverageKeeper.SetTokenHooks(app.OracleKeeper.Hooks())
app.LeverageKeeper.SetBondHooks(app.IncentiveKeeper.BondHooks())

app.GravityKeeper = gravitykeeper.NewKeeper(
keys[gravitytypes.StoreKey],
Expand Down Expand Up @@ -674,6 +683,7 @@ func New(
ica.NewAppModule(nil, &app.ICAHostKeeper),
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 @@ -703,6 +713,7 @@ func New(
paramstypes.ModuleName, vestingtypes.ModuleName,
icatypes.ModuleName, // ibcfeetypes.ModuleName,
leveragetypes.ModuleName,
incentive.ModuleName,
oracletypes.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
Expand All @@ -721,6 +732,7 @@ func New(
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
icatypes.ModuleName, // ibcfeetypes.ModuleName,
leveragetypes.ModuleName,
incentive.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
uibc.ModuleName,
Expand All @@ -743,6 +755,7 @@ func New(

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

oracletypes.ModuleName,
leveragetypes.ModuleName,
incentive.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
uibc.ModuleName,
Expand Down Expand Up @@ -794,10 +808,12 @@ func New(

simStateModules := genmap.Pick(
app.mm.Modules,
[]string{stakingtypes.ModuleName, authtypes.ModuleName, oracletypes.ModuleName,
ibchost.ModuleName},
[]string{
stakingtypes.ModuleName, authtypes.ModuleName, oracletypes.ModuleName,
ibchost.ModuleName,
},
)
// TODO: Ensure x/leverage implements simulator and add it here:
// TODO: Ensure x/leverage, x/incentive implement simulator and add it here:
simTestModules := genmap.Pick(simStateModules,
[]string{oracletypes.ModuleName, ibchost.ModuleName})

Expand Down
14 changes: 13 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/umee-network/umee/v4/app/upgradev3"
"github.com/umee-network/umee/v4/app/upgradev3x3"
"github.com/umee-network/umee/v4/x/incentive"
leveragekeeper "github.com/umee-network/umee/v4/x/leverage/keeper"
leveragetypes "github.com/umee-network/umee/v4/x/leverage/types"
oraclekeeper "github.com/umee-network/umee/v4/x/oracle/keeper"
Expand All @@ -47,6 +48,18 @@ func (app UmeeApp) RegisterUpgradeHandlers(bool) {
app.registerUpgrade4_1(upgradeInfo)
app.registerUpgrade4_2(upgradeInfo)
app.registerUpgrade4_3(upgradeInfo)
app.registerUpgrade4_4(upgradeInfo)
}

// performs upgrade from v4.3 to v4.4
func (app *UmeeApp) registerUpgrade4_4(upgradeInfo upgradetypes.Plan) {
const planName = "v4.4"
app.UpgradeKeeper.SetUpgradeHandler(planName, onlyModuleMigrations(app, planName))
app.storeUpgrade(planName, upgradeInfo, storetypes.StoreUpgrades{
Added: []string{
incentive.ModuleName,
},
})
}

// performs upgrade from v4.2 to v4.3
Expand Down Expand Up @@ -97,7 +110,6 @@ func (app *UmeeApp) registerUpgrade4_3(upgradeInfo upgradetypes.Plan) {
icahosttypes.StoreKey,
},
})

}

// performs upgrade from v4.1 to v4.2
Expand Down
60 changes: 28 additions & 32 deletions proto/umee/incentive/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package umeenetwork.umee.incentive.v1;
package umee.incentive.v1;

option go_package = "github.com/umee-network/umee/v4/x/incentive";

Expand All @@ -11,7 +11,7 @@ import "umee/incentive/v1/incentive.proto";
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
uint32 next_program_id = 2;
uint64 last_rewards_time = 3;
int64 last_rewards_time = 3;
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
repeated RewardTracker reward_trackers = 4 [(gogoproto.nullable) = false];
repeated RewardAccumulator reward_accumulators = 5 [(gogoproto.nullable) = false];
repeated IncentiveProgram upcoming_programs = 6 [(gogoproto.nullable) = false];
Expand All @@ -21,59 +21,55 @@ message GenesisState {
repeated AccountUnbondings account_unbondings = 10 [(gogoproto.nullable) = false];
}

// TotalBond tracks the amount of coins of one uToken denomination bonded to a
// given reward tier by all accounts. Used by queries TotalBonded and TotalUnbonding.
message TotalBond {
uint32 tier = 1;
cosmos.base.v1beta1.Coin amount = 2 [(gogoproto.nullable) = false];
}
toteki marked this conversation as resolved.
Show resolved Hide resolved

// Bond tracks the amount of coins of one uToken denomination bonded to a
// given reward tier by a single account.
// Bond tracks the amount of coins of one uToken denomination bonded
// by a single account.
message Bond {
string account = 1;
uint32 tier = 2;
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin uToken = 2 [(gogoproto.nullable) = false];
}

// RewardTracker tracks the value of a given tier and lock denom's RewardAccumulator
// at the last time a specific account calculated pending rewards for it. When calculating
// RewardTracker tracks the value of a given lock denom's RewardAccumulator at the
// last time a specific account calculated pending rewards for it. When calculating
// available rewards, this value is used to determine the difference between the current
// RewardAccumulator for a tier and the last value at which the user updated bonds or claimed
// RewardAccumulator for a uToken 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;
string uToken = 2;
repeated cosmos.base.v1beta1.DecCoin rewards = 3 [
toteki marked this conversation as resolved.
Show resolved Hide resolved
(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 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 [
string uToken = 1;
repeated cosmos.base.v1beta1.DecCoin rewards = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"
];
uint32 exponent = 3;
}

// Unbonding is a structure that tracks an in-progress token unbonding.
// It tracks both its start time and end time, so that if the module's
// unbonding time changes, the unbonding can complete at the earlier of
// its original end time or its new one based on the new parameter.
message Unbonding {
uint64 end = 1;
cosmos.base.v1beta1.Coin amount = 2 [(gogoproto.nullable) = false];
int64 start = 1;
int64 end = 2;
cosmos.base.v1beta1.Coin uToken = 3 [(gogoproto.nullable) = false];
}

// AccountUnbondings is a structure that is used to store all of an account's unbondings
// for a single bonded uToken denom and and unbonding tier in both KVStore and genesis state.
// for a single bonded uToken denom in both KVStore and genesis state.
message AccountUnbondings {
string account = 1;
string denom = 2;
uint32 tier = 3;
repeated Unbonding unbondings = 4 [(gogoproto.nullable) = false];
}
string uToken = 2;
repeated Unbonding unbondings = 3 [(gogoproto.nullable) = false];
}
46 changes: 11 additions & 35 deletions proto/umee/incentive/v1/incentive.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package umeenetwork.umee.incentive.v1;
package umee.incentive.v1;

import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
Expand All @@ -10,43 +10,19 @@ option go_package = "github.com/umee-network/umee/v4/x/incentive";
message Params {
option (gogoproto.equal) = true;

// max_unbondings defines the maximum amount of concurrent unbondings an address can have
// on each unbonding tier of each bonded uToken denom.
// max_unbondings is the maximum amount of concurrent unbondings an address can have
// of each bonded uToken denom. Zero is interpreted as no limit.
uint32 max_unbondings = 1;

// unbonding_duration_long defines the unbonding duration (in seconds) of the long tier.
uint64 unbonding_duration_long = 2;
// unbonding_duration is the unbonding duration (in seconds).
int64 unbonding_duration = 2;
toteki marked this conversation as resolved.
Show resolved Hide resolved

// unbonding_duration_middle defines the unbonding duration (in seconds) of the middle tier.
uint64 unbonding_duration_middle = 3;

// unbonding_duration_short defines the unbonding duration (in seconds) of the short tier.
uint64 unbonding_duration_short = 4;

// tier_weight_short defines the proportion of rewards which assets bonded
// in the short unbonding duration receive compared to what the same amount
// would receive bonded to the long tier.
// valid values: [0;1]
string tier_weight_short = 5 [
// emergency_unbond_fee is the portion of a bond that is paid when it is instantly
// released using MsgEmergencyUnbond. For example, 0.01 is a 1% fee. Ranges 0-1.
string emergency_unbond_fee = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// tier_weight_middle defines the proportion of rewards which assets bonded
// in the middle unbonding duration receive compared to what the same amount
// would receive bonded to the long tier.
// valid values: [0;1]
string tier_weight_middle = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// community_fund_address is the address from which all incentive programs
// proposed with "from_community_fund = true" will receive their funding.
// Since funds are withdrawn automatically when an incentive program passes
// governance, this account should always contain sufficient balance to
// cover incentive programs which are being voted upon.
string community_fund_address = 7;
}

// IncentiveProgram defines a liquidity mining incentive program on a single
Expand All @@ -62,13 +38,13 @@ message IncentiveProgram {
// start_time is the unix time (in seconds) at which the incentives begin.
// If a program is passed after its intended start time, its start time
// will be increased to the current time, with program duration unchanged.
uint64 start_time = 2;
int64 start_time = 2;

// duration is the length of the incentive program from start time to
// completion in seconds.
uint64 duration = 3;
int64 duration = 3;

// uToken is the incentivized uToken collateral. Suppliers who collateralize
// uToken is the incentivized uToken collateral denom. Suppliers who collateralize
// this asset then bond it to the incentive module are eligible for this program's
// rewards.
string uToken = 4;
Expand Down
Loading