Skip to content

Commit

Permalink
USDX incentive accumulators (#752)
Browse files Browse the repository at this point in the history
* feat: split liquidations between external keepers and automated begin blocker

* wip: refactor usdx minting incentives to use accumulators/hooks

* wip: refactor usdx minting claim object

* feat: use accumulators/hooks for usdx minting rewards

* fix: get tests passing

* fix: don't create claim objects unless that cdp type is eligable for rewards

* add begin blocker

* update client

* cleanup comments/tests

* update querier

* address review comments

* fix: check for division by zero

* address review comments

* run hook before interest is synced

* Remove savings rate (#764)

* remove savings rate

* remove savings rate from debt param

* update migrations

* address review comments

* Add usdx incentives calculation test (#765)

* add usdx incentive calculation test

* update reward calculation

* add allowable error to test criteria

* Update x/incentive/keeper/rewards_test.go

Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>

* fix: remove old fields from test genesis state

Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
  • Loading branch information
karzak and rhuairahrighairidh authored Jan 18, 2021
1 parent c5b05af commit 240c781
Show file tree
Hide file tree
Showing 83 changed files with 31,251 additions and 3,712 deletions.
7 changes: 4 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ var (
auction.ModuleName: nil,
cdp.ModuleName: {supply.Minter, supply.Burner},
cdp.LiquidatorMacc: {supply.Minter, supply.Burner},
cdp.SavingsRateMacc: {supply.Minter},
bep3.ModuleName: {supply.Minter, supply.Burner},
kavadist.ModuleName: {supply.Minter},
issuance.ModuleAccountName: {supply.Minter, supply.Burner},
Expand Down Expand Up @@ -340,7 +339,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts AppOptio
app.supplyKeeper,
auctionSubspace,
)
app.cdpKeeper = cdp.NewKeeper(
cdpKeeper := cdp.NewKeeper(
app.cdc,
keys[cdp.StoreKey],
cdpSubspace,
Expand Down Expand Up @@ -369,7 +368,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts AppOptio
keys[incentive.StoreKey],
incentiveSubspace,
app.supplyKeeper,
app.cdpKeeper,
&cdpKeeper,
app.accountKeeper,
)
app.issuanceKeeper = issuance.NewKeeper(
Expand All @@ -393,6 +392,8 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts AppOptio
app.stakingKeeper = *stakingKeeper.SetHooks(
staking.NewMultiStakingHooks(app.distrKeeper.Hooks(), app.slashingKeeper.Hooks()))

app.cdpKeeper = *cdpKeeper.SetHooks(cdp.NewMultiCDPHooks(app.incentiveKeeper.Hooks()))

// create the module manager (Note: Any module instantiated in the module manager that is later modified
// must be passed by reference here.)
app.mm = module.NewManager(
Expand Down
3 changes: 1 addition & 2 deletions migrate/v0_11/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
v0_11committee "github.com/kava-labs/kava/x/committee"
v0_9committee "github.com/kava-labs/kava/x/committee/legacy/v0_9"
v0_11harvest "github.com/kava-labs/kava/x/harvest/legacy/v0_11"
v0_11incentive "github.com/kava-labs/kava/x/incentive"
v0_11incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_11"
v0_9incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_9"
v0_11issuance "github.com/kava-labs/kava/x/issuance"
v0_11pricefeed "github.com/kava-labs/kava/x/pricefeed"
Expand Down Expand Up @@ -308,7 +308,6 @@ func MigrateCommittee(oldGenState v0_9committee.GenesisState) v0_11committee.Gen
DebtFloor: oldDebtParam.DebtFloor,
Denom: oldDebtParam.Denom,
ReferenceAsset: oldDebtParam.ReferenceAsset,
SavingsRate: oldDebtParam.SavingsRate,
}
oldAssetParam := subPermission.AllowedAssetParams[0]
newAssetParam := v0_11committee.AllowedAssetParam{
Expand Down
25 changes: 0 additions & 25 deletions migrate/v0_11/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
v39_1auth "github.com/cosmos/cosmos-sdk/x/auth"
v39_1auth_vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/genutil"
v39_1supply "github.com/cosmos/cosmos-sdk/x/supply"

tmtypes "github.com/tendermint/tendermint/types"

"github.com/kava-labs/kava/app"
v38_5auth "github.com/kava-labs/kava/migrate/v0_11/legacy/cosmos-sdk/v0.38.5/auth"
v38_5supply "github.com/kava-labs/kava/migrate/v0_11/legacy/cosmos-sdk/v0.38.5/supply"
Expand Down Expand Up @@ -167,25 +164,3 @@ func TestMigratePricefeed(t *testing.T) {
err = newGenState.Validate()
require.NoError(t, err)
}

func TestMigrateFull(t *testing.T) {
oldGenDoc, err := tmtypes.GenesisDocFromFile(filepath.Join("testdata", "kava-3-export.json"))
require.NoError(t, err)

// 2) migrate
newGenDoc := Migrate(*oldGenDoc)
tApp := app.NewTestApp()
cdc := app.MakeCodec()
var newAppState genutil.AppMap
require.NoError(t,
cdc.UnmarshalJSON(newGenDoc.AppState, &newAppState),
)
err = app.ModuleBasics.ValidateGenesis(newAppState)
if err != nil {
require.NoError(t, err)
}
require.NotPanics(t, func() {
// this runs both InitGenesis for all modules (which panic on errors) and runs all invariants
tApp.InitializeFromGenesisStatesWithTime(newGenDoc.GenesisTime, app.GenesisState(newAppState))
})
}
6 changes: 2 additions & 4 deletions migrate/v0_13/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func MigrateCDP(oldGenState v0_11cdp.GenesisState) v0_13cdp.GenesisState {

oldDebtParam := oldGenState.Params.DebtParam

newDebtParam := v0_13cdp.NewDebtParam(oldDebtParam.Denom, oldDebtParam.ReferenceAsset, oldDebtParam.ConversionFactor, oldDebtParam.DebtFloor, oldDebtParam.SavingsRate)
newDebtParam := v0_13cdp.NewDebtParam(oldDebtParam.Denom, oldDebtParam.ReferenceAsset, oldDebtParam.ConversionFactor, oldDebtParam.DebtFloor)

newGlobalDebtLimit := oldGenState.Params.GlobalDebtLimit

newParams := v0_13cdp.NewParams(newGlobalDebtLimit, newCollateralParams, newDebtParam, oldGenState.Params.SurplusAuctionThreshold, oldGenState.Params.SurplusAuctionLot, oldGenState.Params.DebtAuctionThreshold, oldGenState.Params.DebtAuctionLot, oldGenState.Params.SavingsDistributionFrequency, false)
newParams := v0_13cdp.NewParams(newGlobalDebtLimit, newCollateralParams, newDebtParam, oldGenState.Params.SurplusAuctionThreshold, oldGenState.Params.SurplusAuctionLot, oldGenState.Params.DebtAuctionThreshold, oldGenState.Params.DebtAuctionLot, false)

return v0_13cdp.NewGenesisState(
newParams,
Expand All @@ -63,8 +63,6 @@ func MigrateCDP(oldGenState v0_11cdp.GenesisState) v0_13cdp.GenesisState {
newStartingID,
oldGenState.DebtDenom,
oldGenState.GovDenom,
oldGenState.PreviousDistributionTime,
sdk.ZeroInt(),
newGenesisAccumulationTimes,
totalPrincipals,
)
Expand Down
Loading

0 comments on commit 240c781

Please sign in to comment.