mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-20 15:05:21 +00:00
Incentive module multiple reward denom tests (#788)
* types: multiple rewards * supply-side reward keeper methods * remove legacy comments * update hard claim reward to coins type * borrow-side reward keeper methods * update claim payout to sdk.Coins * make tests compile * fix genesis validation for compile * comment out failing tests * fix ! found logic * accumulate hard supply rewards (single) * sync hard supply rewards (single) * update hard borrow/supply index denoms * accumulate hard borrow rewards (single) * sync hard borrow rewards (single) * sync hard delegator rewards * payout hard claim (single) * accumulate hard supply rewards (multiple) * sync hard supply rewards (multiple) * update hard supply index denoms (multiple) * update hard borrow index denoms (multiple) * accumulate hard borrow rewards (multiple) * sync hard borrow rewards (multiple) * fix denom * remove comment * fix merge * payout hard reward (multiple) Co-authored-by: karzak <kjydavis3@gmail.com>
This commit is contained in:
parent
0c1fa5d27b
commit
754c018f04
@ -107,6 +107,9 @@ func (k Keeper) ClaimHardReward(ctx sdk.Context, addr sdk.AccAddress, multiplier
|
||||
}
|
||||
rewardCoins = append(rewardCoins, sdk.NewCoin(coin.Denom, rewardAmount))
|
||||
}
|
||||
if rewardCoins.IsZero() {
|
||||
return types.ErrZeroClaim
|
||||
}
|
||||
length, err := k.GetPeriodLength(ctx, multiplier)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/kava-labs/kava/app"
|
||||
cdptypes "github.com/kava-labs/kava/x/cdp/types"
|
||||
"github.com/kava-labs/kava/x/hard"
|
||||
"github.com/kava-labs/kava/x/incentive/types"
|
||||
"github.com/kava-labs/kava/x/kavadist"
|
||||
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
|
||||
@ -153,179 +154,281 @@ func (suite *KeeperTestSuite) TestPayoutUSDXMintingClaim() {
|
||||
}
|
||||
}
|
||||
|
||||
// func (suite *KeeperTestSuite) TestPayoutHardLiquidityProviderClaim() {
|
||||
// type args struct {
|
||||
// deposit sdk.Coins
|
||||
// borrow sdk.Coins
|
||||
// rewardsPerSecond sdk.Coin
|
||||
// initialTime time.Time
|
||||
// multipliers types.Multipliers
|
||||
// multiplier types.MultiplierName
|
||||
// timeElapsed int64
|
||||
// expectedReward sdk.Coin
|
||||
// expectedPeriods vesting.Periods
|
||||
// isPeriodicVestingAccount bool
|
||||
// }
|
||||
// type errArgs struct {
|
||||
// expectPass bool
|
||||
// contains string
|
||||
// }
|
||||
// type test struct {
|
||||
// name string
|
||||
// args args
|
||||
// errArgs errArgs
|
||||
// }
|
||||
// testCases := []test{
|
||||
// {
|
||||
// "valid 1 day",
|
||||
// args{
|
||||
// deposit: cs(c("bnb", 10000000000)),
|
||||
// borrow: cs(c("bnb", 5000000000)),
|
||||
// rewardsPerSecond: c("hard", 122354),
|
||||
// initialTime: time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC),
|
||||
// multipliers: types.Multipliers{types.NewMultiplier(types.MultiplierName("small"), 1, d("0.25")), types.NewMultiplier(types.MultiplierName("large"), 12, d("1.0"))},
|
||||
// multiplier: types.MultiplierName("large"),
|
||||
// timeElapsed: 86400,
|
||||
// expectedReward: c("hard", 21142771200), // 10571385600 (deposit reward) + 10571385600 (borrow reward)
|
||||
// expectedPeriods: vesting.Periods{vesting.Period{Length: 31536000, Amount: cs(c("hard", 21142771200))}},
|
||||
// isPeriodicVestingAccount: true,
|
||||
// },
|
||||
// errArgs{
|
||||
// expectPass: true,
|
||||
// contains: "",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// "invalid zero rewards",
|
||||
// args{
|
||||
// deposit: cs(c("bnb", 10000000000)),
|
||||
// borrow: cs(c("bnb", 5000000000)),
|
||||
// rewardsPerSecond: c("hard", 0),
|
||||
// initialTime: time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC),
|
||||
// multipliers: types.Multipliers{types.NewMultiplier(types.MultiplierName("small"), 1, d("0.25")), types.NewMultiplier(types.MultiplierName("large"), 12, d("1.0"))},
|
||||
// multiplier: types.MultiplierName("large"),
|
||||
// timeElapsed: 86400,
|
||||
// expectedReward: sdk.Coin{},
|
||||
// expectedPeriods: vesting.Periods{},
|
||||
// isPeriodicVestingAccount: false,
|
||||
// },
|
||||
// errArgs{
|
||||
// expectPass: false,
|
||||
// contains: "claim amount rounds to zero",
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
func (suite *KeeperTestSuite) TestPayoutHardLiquidityProviderClaim() {
|
||||
type args struct {
|
||||
deposit sdk.Coins
|
||||
borrow sdk.Coins
|
||||
rewardsPerSecond sdk.Coins
|
||||
initialTime time.Time
|
||||
multipliers types.Multipliers
|
||||
multiplier types.MultiplierName
|
||||
timeElapsed int64
|
||||
expectedRewards sdk.Coins
|
||||
expectedPeriods vesting.Periods
|
||||
isPeriodicVestingAccount bool
|
||||
}
|
||||
type errArgs struct {
|
||||
expectPass bool
|
||||
contains string
|
||||
}
|
||||
type test struct {
|
||||
name string
|
||||
args args
|
||||
errArgs errArgs
|
||||
}
|
||||
testCases := []test{
|
||||
{
|
||||
"single reward denom: valid 1 day",
|
||||
args{
|
||||
deposit: cs(c("bnb", 10000000000)),
|
||||
borrow: cs(c("bnb", 5000000000)),
|
||||
rewardsPerSecond: cs(c("hard", 122354)),
|
||||
initialTime: time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC),
|
||||
multipliers: types.Multipliers{types.NewMultiplier(types.MultiplierName("small"), 1, d("0.25")), types.NewMultiplier(types.MultiplierName("large"), 12, d("1.0"))},
|
||||
multiplier: types.MultiplierName("large"),
|
||||
timeElapsed: 86400,
|
||||
expectedRewards: cs(c("hard", 21142771200)), // 10571385600 (deposit reward) + 10571385600 (borrow reward)
|
||||
expectedPeriods: vesting.Periods{vesting.Period{Length: 32918400, Amount: cs(c("hard", 21142771200))}},
|
||||
isPeriodicVestingAccount: true,
|
||||
},
|
||||
errArgs{
|
||||
expectPass: true,
|
||||
contains: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
"single reward denom: valid 10 days",
|
||||
args{
|
||||
deposit: cs(c("bnb", 10000000000)),
|
||||
borrow: cs(c("bnb", 5000000000)),
|
||||
rewardsPerSecond: cs(c("hard", 122354)),
|
||||
initialTime: time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC),
|
||||
multipliers: types.Multipliers{types.NewMultiplier(types.MultiplierName("small"), 1, d("0.25")), types.NewMultiplier(types.MultiplierName("large"), 12, d("1.0"))},
|
||||
multiplier: types.MultiplierName("large"),
|
||||
timeElapsed: 864000,
|
||||
expectedRewards: cs(c("hard", 211427712000)), // 105713856000 (deposit reward) + 105713856000 (borrow reward)
|
||||
expectedPeriods: vesting.Periods{vesting.Period{Length: 32140800, Amount: cs(c("hard", 211427712000))}},
|
||||
isPeriodicVestingAccount: true,
|
||||
},
|
||||
errArgs{
|
||||
expectPass: true,
|
||||
contains: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
"invalid zero rewards",
|
||||
args{
|
||||
deposit: cs(c("bnb", 10000000000)),
|
||||
borrow: cs(c("bnb", 5000000000)),
|
||||
rewardsPerSecond: cs(c("hard", 0)),
|
||||
initialTime: time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC),
|
||||
multipliers: types.Multipliers{types.NewMultiplier(types.MultiplierName("small"), 1, d("0.25")), types.NewMultiplier(types.MultiplierName("large"), 12, d("1.0"))},
|
||||
multiplier: types.MultiplierName("large"),
|
||||
timeElapsed: 86400,
|
||||
expectedRewards: cs(c("hard", 0)),
|
||||
expectedPeriods: vesting.Periods{},
|
||||
isPeriodicVestingAccount: false,
|
||||
},
|
||||
errArgs{
|
||||
expectPass: false,
|
||||
contains: "claim amount rounds to zero",
|
||||
},
|
||||
},
|
||||
{
|
||||
"multiple reward denoms: valid 1 day",
|
||||
args{
|
||||
deposit: cs(c("bnb", 10000000000)),
|
||||
borrow: cs(c("bnb", 5000000000)),
|
||||
rewardsPerSecond: cs(c("hard", 122354), c("ukava", 122354)),
|
||||
initialTime: time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC),
|
||||
multipliers: types.Multipliers{types.NewMultiplier(types.MultiplierName("small"), 1, d("0.25")), types.NewMultiplier(types.MultiplierName("large"), 12, d("1.0"))},
|
||||
multiplier: types.MultiplierName("large"),
|
||||
timeElapsed: 86400,
|
||||
expectedRewards: cs(c("hard", 21142771200), c("ukava", 21142771200)), // 10571385600 (deposit reward) + 10571385600 (borrow reward)
|
||||
expectedPeriods: vesting.Periods{vesting.Period{Length: 32918400, Amount: cs(c("hard", 21142771200), c("ukava", 21142771200))}},
|
||||
isPeriodicVestingAccount: true,
|
||||
},
|
||||
errArgs{
|
||||
expectPass: true,
|
||||
contains: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
"multiple reward denoms: valid 10 days",
|
||||
args{
|
||||
deposit: cs(c("bnb", 10000000000)),
|
||||
borrow: cs(c("bnb", 5000000000)),
|
||||
rewardsPerSecond: cs(c("hard", 122354), c("ukava", 122354)),
|
||||
initialTime: time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC),
|
||||
multipliers: types.Multipliers{types.NewMultiplier(types.MultiplierName("small"), 1, d("0.25")), types.NewMultiplier(types.MultiplierName("large"), 12, d("1.0"))},
|
||||
multiplier: types.MultiplierName("large"),
|
||||
timeElapsed: 864000,
|
||||
expectedRewards: cs(c("hard", 211427712000), c("ukava", 211427712000)), // 105713856000 (deposit reward) + 105713856000 (borrow reward)
|
||||
expectedPeriods: vesting.Periods{vesting.Period{Length: 32140800, Amount: cs(c("hard", 211427712000), c("ukava", 211427712000))}},
|
||||
isPeriodicVestingAccount: true,
|
||||
},
|
||||
errArgs{
|
||||
expectPass: true,
|
||||
contains: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
"multiple reward denoms with different rewards per second: valid 1 day",
|
||||
args{
|
||||
deposit: cs(c("bnb", 10000000000)),
|
||||
borrow: cs(c("bnb", 5000000000)),
|
||||
rewardsPerSecond: cs(c("hard", 122354), c("ukava", 222222)),
|
||||
initialTime: time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC),
|
||||
multipliers: types.Multipliers{types.NewMultiplier(types.MultiplierName("small"), 1, d("0.25")), types.NewMultiplier(types.MultiplierName("large"), 12, d("1.0"))},
|
||||
multiplier: types.MultiplierName("large"),
|
||||
timeElapsed: 86400,
|
||||
expectedRewards: cs(c("hard", 21142771200), c("ukava", 38399961600)),
|
||||
expectedPeriods: vesting.Periods{vesting.Period{Length: 32918400, Amount: cs(c("hard", 21142771200), c("ukava", 38399961600))}},
|
||||
isPeriodicVestingAccount: true,
|
||||
},
|
||||
errArgs{
|
||||
expectPass: true,
|
||||
contains: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// for _, tc := range testCases {
|
||||
// suite.Run(tc.name, func() {
|
||||
// suite.SetupWithGenState()
|
||||
// suite.ctx = suite.ctx.WithBlockTime(tc.args.initialTime)
|
||||
for _, tc := range testCases {
|
||||
suite.Run(tc.name, func() {
|
||||
suite.SetupWithGenState()
|
||||
suite.ctx = suite.ctx.WithBlockTime(tc.args.initialTime)
|
||||
|
||||
// // setup kavadist state
|
||||
// sk := suite.app.GetSupplyKeeper()
|
||||
// err := sk.MintCoins(suite.ctx, kavadist.ModuleName, cs(c("hard", 1000000000000)))
|
||||
// suite.Require().NoError(err)
|
||||
// setup kavadist state
|
||||
sk := suite.app.GetSupplyKeeper()
|
||||
err := sk.MintCoins(suite.ctx, kavadist.ModuleName, cs(c("hard", 1000000000000000000), c("ukava", 1000000000000000000)))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// // Set up generic reward periods
|
||||
// var multiRewardPeriods types.MultiRewardPeriods
|
||||
// var rewardPeriods types.RewardPeriods
|
||||
// for _, coin := range tc.args.deposit {
|
||||
// rewardPeriod := types.NewRewardPeriod(true, coin.Denom, tc.args.initialTime, tc.args.initialTime.Add(time.Hour*24*365*4), tc.args.rewardsPerSecond)
|
||||
// rewardPeriods = append(rewardPeriods, rewardPeriod)
|
||||
// multiRewardPeriod := types.NewMultiRewardPeriod(true, coin.Denom, tc.args.initialTime, tc.args.initialTime.Add(time.Hour*24*365*4), cs(tc.args.rewardsPerSecond))
|
||||
// multiRewardPeriods = append(multiRewardPeriods, multiRewardPeriod)
|
||||
// }
|
||||
// Set up generic reward periods
|
||||
var multiRewardPeriods types.MultiRewardPeriods
|
||||
var rewardPeriods types.RewardPeriods
|
||||
for _, coin := range tc.args.deposit {
|
||||
if len(tc.args.rewardsPerSecond) > 0 {
|
||||
rewardPeriod := types.NewRewardPeriod(true, coin.Denom, tc.args.initialTime, tc.args.initialTime.Add(time.Hour*24*365*4), tc.args.rewardsPerSecond[0])
|
||||
rewardPeriods = append(rewardPeriods, rewardPeriod)
|
||||
}
|
||||
multiRewardPeriod := types.NewMultiRewardPeriod(true, coin.Denom, tc.args.initialTime, tc.args.initialTime.Add(time.Hour*24*365*4), tc.args.rewardsPerSecond)
|
||||
multiRewardPeriods = append(multiRewardPeriods, multiRewardPeriod)
|
||||
}
|
||||
|
||||
// // Set up incentive state
|
||||
// params := types.NewParams(
|
||||
// rewardPeriods, multiRewardPeriods, multiRewardPeriods, rewardPeriods,
|
||||
// tc.args.multipliers,
|
||||
// tc.args.initialTime.Add(time.Hour*24*365*5),
|
||||
// )
|
||||
// suite.keeper.SetParams(suite.ctx, params)
|
||||
// Set up generic reward periods
|
||||
params := types.NewParams(
|
||||
rewardPeriods, multiRewardPeriods, multiRewardPeriods, rewardPeriods,
|
||||
types.Multipliers{types.NewMultiplier(types.MultiplierName("small"), 1, d("0.25")), types.NewMultiplier(types.MultiplierName("large"), 12, d("1.0"))},
|
||||
tc.args.initialTime.Add(time.Hour*24*365*5),
|
||||
)
|
||||
suite.keeper.SetParams(suite.ctx, params)
|
||||
|
||||
// // Set each denom's previous accrual time and supply reward factor
|
||||
// for _, coin := range tc.args.deposit {
|
||||
// suite.keeper.SetPreviousHardSupplyRewardAccrualTime(suite.ctx, coin.Denom, tc.args.initialTime)
|
||||
// defaultRewardIndexes := types.RewardIndexes{types.NewRewardIndex(types.HardLiquidityRewardDenom, sdk.ZeroDec())}
|
||||
// suite.keeper.SetHardSupplyRewardIndexes(suite.ctx, coin.Denom, defaultRewardIndexes)
|
||||
// }
|
||||
// for _, coin := range tc.args.borrow {
|
||||
// suite.keeper.SetPreviousHardBorrowRewardAccrualTime(suite.ctx, coin.Denom, tc.args.initialTime)
|
||||
// defaultRewardIndexes := types.RewardIndexes{types.NewRewardIndex(types.HardLiquidityRewardDenom, sdk.ZeroDec())}
|
||||
// suite.keeper.SetHardBorrowRewardIndexes(suite.ctx, coin.Denom, defaultRewardIndexes)
|
||||
// }
|
||||
// Set each denom's previous accrual time and supply reward factor
|
||||
if len(tc.args.rewardsPerSecond) > 0 {
|
||||
for _, coin := range tc.args.deposit {
|
||||
suite.keeper.SetPreviousHardSupplyRewardAccrualTime(suite.ctx, coin.Denom, tc.args.initialTime)
|
||||
var rewardIndexes types.RewardIndexes
|
||||
for _, rewardCoin := range tc.args.rewardsPerSecond {
|
||||
rewardIndex := types.NewRewardIndex(rewardCoin.Denom, sdk.ZeroDec())
|
||||
rewardIndexes = append(rewardIndexes, rewardIndex)
|
||||
}
|
||||
suite.keeper.SetHardSupplyRewardIndexes(suite.ctx, coin.Denom, rewardIndexes)
|
||||
}
|
||||
}
|
||||
|
||||
// hardKeeper := suite.app.GetHardKeeper()
|
||||
// userAddr := suite.addrs[3]
|
||||
// Set each denom's previous accrual time and borrow reward factor
|
||||
if len(tc.args.rewardsPerSecond) > 0 {
|
||||
for _, coin := range tc.args.borrow {
|
||||
suite.keeper.SetPreviousHardBorrowRewardAccrualTime(suite.ctx, coin.Denom, tc.args.initialTime)
|
||||
var rewardIndexes types.RewardIndexes
|
||||
for _, rewardCoin := range tc.args.rewardsPerSecond {
|
||||
rewardIndex := types.NewRewardIndex(rewardCoin.Denom, sdk.ZeroDec())
|
||||
rewardIndexes = append(rewardIndexes, rewardIndex)
|
||||
}
|
||||
suite.keeper.SetHardBorrowRewardIndexes(suite.ctx, coin.Denom, rewardIndexes)
|
||||
}
|
||||
}
|
||||
|
||||
// // User deposits
|
||||
// err = hardKeeper.Deposit(suite.ctx, userAddr, tc.args.deposit)
|
||||
// suite.Require().NoError(err)
|
||||
hardKeeper := suite.app.GetHardKeeper()
|
||||
userAddr := suite.addrs[3]
|
||||
|
||||
// // User borrows
|
||||
// err = hardKeeper.Borrow(suite.ctx, userAddr, tc.args.borrow)
|
||||
// suite.Require().NoError(err)
|
||||
// User deposits and borrows
|
||||
err = hardKeeper.Deposit(suite.ctx, userAddr, tc.args.deposit)
|
||||
suite.Require().NoError(err)
|
||||
err = hardKeeper.Borrow(suite.ctx, userAddr, tc.args.borrow)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// // Check that Hard hooks initialized a HardLiquidityProviderClaim that has 0 rewards
|
||||
// claim, found := suite.keeper.GetHardLiquidityProviderClaim(suite.ctx, suite.addrs[3])
|
||||
// suite.Require().True(found)
|
||||
// for _, coin := range tc.args.deposit {
|
||||
// suite.Require().Equal(sdk.ZeroInt(), claim.Reward.AmountOf(coin.Denom))
|
||||
// }
|
||||
// Check that Hard hooks initialized a HardLiquidityProviderClaim that has 0 rewards
|
||||
claim, found := suite.keeper.GetHardLiquidityProviderClaim(suite.ctx, suite.addrs[3])
|
||||
suite.Require().True(found)
|
||||
for _, coin := range tc.args.deposit {
|
||||
suite.Require().Equal(sdk.ZeroInt(), claim.Reward.AmountOf(coin.Denom))
|
||||
}
|
||||
|
||||
// // Set up future runtime context
|
||||
// runAtTime := time.Unix(suite.ctx.BlockTime().Unix()+(tc.args.timeElapsed), 0)
|
||||
// runCtx := suite.ctx.WithBlockTime(runAtTime)
|
||||
// Set up future runtime context
|
||||
runAtTime := time.Unix(suite.ctx.BlockTime().Unix()+(tc.args.timeElapsed), 0)
|
||||
runCtx := suite.ctx.WithBlockTime(runAtTime)
|
||||
|
||||
// // Run Hard begin blocker
|
||||
// hard.BeginBlocker(runCtx, suite.hardKeeper)
|
||||
// Run Hard begin blocker
|
||||
hard.BeginBlocker(runCtx, suite.hardKeeper)
|
||||
|
||||
// // Accumulate supply rewards for each deposit denom
|
||||
// for _, coin := range tc.args.deposit {
|
||||
// rewardPeriod, found := suite.keeper.GetHardSupplyRewardPeriods(runCtx, coin.Denom)
|
||||
// suite.Require().True(found)
|
||||
// err = suite.keeper.AccumulateHardSupplyRewards(runCtx, rewardPeriod)
|
||||
// suite.Require().NoError(err)
|
||||
// }
|
||||
// Accumulate supply rewards for each deposit denom
|
||||
for _, coin := range tc.args.deposit {
|
||||
rewardPeriod, found := suite.keeper.GetHardSupplyRewardPeriods(runCtx, coin.Denom)
|
||||
suite.Require().True(found)
|
||||
err = suite.keeper.AccumulateHardSupplyRewards(runCtx, rewardPeriod)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// // Accumulate borrow rewards for each deposit denom
|
||||
// for _, coin := range tc.args.borrow {
|
||||
// rewardPeriod, found := suite.keeper.GetHardBorrowRewardPeriods(runCtx, coin.Denom)
|
||||
// suite.Require().True(found)
|
||||
// err = suite.keeper.AccumulateHardBorrowRewards(runCtx, rewardPeriod)
|
||||
// suite.Require().NoError(err)
|
||||
// }
|
||||
// Accumulate borrow rewards for each deposit denom
|
||||
for _, coin := range tc.args.borrow {
|
||||
rewardPeriod, found := suite.keeper.GetHardBorrowRewardPeriods(runCtx, coin.Denom)
|
||||
suite.Require().True(found)
|
||||
err = suite.keeper.AccumulateHardBorrowRewards(runCtx, rewardPeriod)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// // Fetch pre-claim balances
|
||||
// ak := suite.app.GetAccountKeeper()
|
||||
// preClaimAcc := ak.GetAccount(runCtx, suite.addrs[3])
|
||||
// Sync hard supply rewards
|
||||
deposit, found := suite.hardKeeper.GetDeposit(suite.ctx, suite.addrs[3])
|
||||
suite.Require().True(found)
|
||||
suite.keeper.SynchronizeHardSupplyReward(suite.ctx, deposit)
|
||||
|
||||
// err = suite.keeper.ClaimHardReward(runCtx, suite.addrs[3], tc.args.multiplier)
|
||||
// if tc.errArgs.expectPass {
|
||||
// suite.Require().NoError(err)
|
||||
// Sync hard borrow rewards
|
||||
borrow, found := suite.hardKeeper.GetBorrow(suite.ctx, suite.addrs[3])
|
||||
suite.Require().True(found)
|
||||
suite.keeper.SynchronizeHardBorrowReward(suite.ctx, borrow)
|
||||
|
||||
// // Check that user's balance has increased by expected reward amount
|
||||
// postClaimAcc := ak.GetAccount(suite.ctx, suite.addrs[3])
|
||||
// suite.Require().Equal(preClaimAcc.GetCoins().Add(tc.args.expectedReward), postClaimAcc.GetCoins())
|
||||
// Fetch pre-claim balances
|
||||
ak := suite.app.GetAccountKeeper()
|
||||
preClaimAcc := ak.GetAccount(runCtx, suite.addrs[3])
|
||||
|
||||
// if tc.args.isPeriodicVestingAccount {
|
||||
// vacc, ok := postClaimAcc.(*vesting.PeriodicVestingAccount)
|
||||
// suite.Require().True(ok)
|
||||
// suite.Require().Equal(tc.args.expectedPeriods, vacc.VestingPeriods)
|
||||
// }
|
||||
err = suite.keeper.ClaimHardReward(runCtx, suite.addrs[3], tc.args.multiplier)
|
||||
if tc.errArgs.expectPass {
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// // Check that the claim's reward amount has been reset to 0
|
||||
// claim, found := suite.keeper.GetHardLiquidityProviderClaim(runCtx, suite.addrs[3])
|
||||
// suite.Require().True(found)
|
||||
// suite.Require().Equal(c("hard", 0), claim.Reward)
|
||||
// } else {
|
||||
// suite.Require().Error(err)
|
||||
// suite.Require().True(strings.Contains(err.Error(), tc.errArgs.contains))
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
// Check that user's balance has increased by expected reward amount
|
||||
postClaimAcc := ak.GetAccount(suite.ctx, suite.addrs[3])
|
||||
suite.Require().Equal(preClaimAcc.GetCoins().Add(tc.args.expectedRewards...), postClaimAcc.GetCoins())
|
||||
|
||||
if tc.args.isPeriodicVestingAccount {
|
||||
vacc, ok := postClaimAcc.(*vesting.PeriodicVestingAccount)
|
||||
suite.Require().True(ok)
|
||||
suite.Require().Equal(tc.args.expectedPeriods, vacc.VestingPeriods)
|
||||
}
|
||||
|
||||
// Check that each claim reward coin's amount has been reset to 0
|
||||
claim, found := suite.keeper.GetHardLiquidityProviderClaim(runCtx, suite.addrs[3])
|
||||
suite.Require().True(found)
|
||||
for _, claimRewardCoin := range claim.Reward {
|
||||
suite.Require().Equal(c(claimRewardCoin.Denom, 0), claimRewardCoin)
|
||||
}
|
||||
} else {
|
||||
suite.Require().Error(err)
|
||||
suite.Require().True(strings.Contains(err.Error(), tc.errArgs.contains))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestSendCoinsToPeriodicVestingAccount() {
|
||||
type accountArgs struct {
|
||||
|
@ -301,16 +301,17 @@ func (k Keeper) SynchronizeHardSupplyReward(ctx sdk.Context, deposit hardtypes.D
|
||||
continue
|
||||
}
|
||||
|
||||
userRewardIndexIndex, foundUserRewardIndexIndex := claim.SupplyRewardIndexes.GetRewardIndexIndex(coin.Denom)
|
||||
if !foundUserRewardIndexIndex {
|
||||
fmt.Printf("\n[LOG]: factor index for %s should always be found", coin.Denom) // TODO: remove before production
|
||||
continue
|
||||
}
|
||||
|
||||
for _, globalRewardIndex := range globalRewardIndexes {
|
||||
userRewardIndex, foundUserRewardIndex := userRewardIndexes.RewardIndexes.GetRewardIndex(globalRewardIndex.CollateralType)
|
||||
if !foundUserRewardIndex {
|
||||
continue
|
||||
}
|
||||
userRewardIndexIndex, foundUserRewardIndexIndex := userRewardIndexes.RewardIndexes.GetFactorIndex(globalRewardIndex.CollateralType)
|
||||
if !foundUserRewardIndexIndex {
|
||||
fmt.Printf("\n[LOG]: factor index for %s should always be found", coin.Denom) // TODO: remove before production
|
||||
continue
|
||||
}
|
||||
|
||||
globalRewardFactor := globalRewardIndex.RewardFactor
|
||||
userRewardFactor := userRewardIndex.RewardFactor
|
||||
@ -377,16 +378,17 @@ func (k Keeper) SynchronizeHardBorrowReward(ctx sdk.Context, borrow hardtypes.Bo
|
||||
continue
|
||||
}
|
||||
|
||||
userRewardIndexIndex, foundUserRewardIndexIndex := claim.BorrowRewardIndexes.GetRewardIndexIndex(coin.Denom)
|
||||
if !foundUserRewardIndexIndex {
|
||||
fmt.Printf("\n[LOG]: factor index for %s should always be found", coin.Denom) // TODO: remove before production
|
||||
continue
|
||||
}
|
||||
|
||||
for _, globalRewardIndex := range globalRewardIndexes {
|
||||
userRewardIndex, foundUserRewardIndex := userRewardIndexes.RewardIndexes.GetRewardIndex(globalRewardIndex.CollateralType)
|
||||
if !foundUserRewardIndex {
|
||||
continue
|
||||
}
|
||||
userRewardIndexIndex, foundUserRewardIndexIndex := userRewardIndexes.RewardIndexes.GetFactorIndex(globalRewardIndex.CollateralType)
|
||||
if !foundUserRewardIndexIndex {
|
||||
fmt.Printf("\n[LOG]: factor index for %s should always be found", coin.Denom) // TODO: remove before production
|
||||
continue
|
||||
}
|
||||
|
||||
globalRewardFactor := globalRewardIndex.RewardFactor
|
||||
userRewardFactor := userRewardIndex.RewardFactor
|
||||
@ -616,11 +618,11 @@ func (k Keeper) SynchronizeHardLiquidityProviderClaim(ctx sdk.Context, owner sdk
|
||||
k.SynchronizeHardSupplyReward(ctx, deposit)
|
||||
}
|
||||
|
||||
// // Synchronize any hard liquidity borrow-side rewards
|
||||
// borrow, foundBorrow := k.hardKeeper.GetBorrow(ctx, owner)
|
||||
// if foundBorrow {
|
||||
// k.SynchronizeHardBorrowReward(ctx, borrow)
|
||||
// }
|
||||
// Synchronize any hard liquidity borrow-side rewards
|
||||
borrow, foundBorrow := k.hardKeeper.GetBorrow(ctx, owner)
|
||||
if foundBorrow {
|
||||
k.SynchronizeHardBorrowReward(ctx, borrow)
|
||||
}
|
||||
|
||||
// Synchronize any hard delegator rewards
|
||||
k.SynchronizeHardDelegatorRewards(ctx, owner)
|
||||
@ -668,16 +670,17 @@ func (k Keeper) SimulateHardSynchronization(ctx sdk.Context, claim types.HardLiq
|
||||
continue
|
||||
}
|
||||
|
||||
userRewardIndexIndex, foundUserRewardIndexIndex := claim.SupplyRewardIndexes.GetRewardIndexIndex(ri.CollateralType)
|
||||
if !foundUserRewardIndexIndex {
|
||||
fmt.Printf("\n[LOG]: factor index for %s should always be found", ri.CollateralType) // TODO: remove before production
|
||||
continue
|
||||
}
|
||||
|
||||
for _, globalRewardIndex := range globalRewardIndexes {
|
||||
userRewardIndex, foundUserRewardIndex := userRewardIndexes.RewardIndexes.GetRewardIndex(globalRewardIndex.CollateralType)
|
||||
if !foundUserRewardIndex {
|
||||
continue
|
||||
}
|
||||
userRewardIndexIndex, foundUserRewardIndexIndex := userRewardIndexes.RewardIndexes.GetFactorIndex(globalRewardIndex.CollateralType)
|
||||
if !foundUserRewardIndexIndex {
|
||||
fmt.Printf("\n[LOG]: factor index for %s should always be found", ri.CollateralType) // TODO: remove before production
|
||||
continue
|
||||
}
|
||||
|
||||
globalRewardFactor := globalRewardIndex.RewardFactor
|
||||
userRewardFactor := userRewardIndex.RewardFactor
|
||||
@ -717,16 +720,17 @@ func (k Keeper) SimulateHardSynchronization(ctx sdk.Context, claim types.HardLiq
|
||||
continue
|
||||
}
|
||||
|
||||
userRewardIndexIndex, foundUserRewardIndexIndex := claim.BorrowRewardIndexes.GetRewardIndexIndex(ri.CollateralType)
|
||||
if !foundUserRewardIndexIndex {
|
||||
fmt.Printf("\n[LOG]: factor index for %s should always be found", ri.CollateralType) // TODO: remove before production
|
||||
continue
|
||||
}
|
||||
|
||||
for _, globalRewardIndex := range globalRewardIndexes {
|
||||
userRewardIndex, foundUserRewardIndex := userRewardIndexes.RewardIndexes.GetRewardIndex(globalRewardIndex.CollateralType)
|
||||
if !foundUserRewardIndex {
|
||||
continue
|
||||
}
|
||||
userRewardIndexIndex, foundUserRewardIndexIndex := userRewardIndexes.RewardIndexes.GetFactorIndex(globalRewardIndex.CollateralType)
|
||||
if !foundUserRewardIndexIndex {
|
||||
fmt.Printf("\n[LOG]: factor index for %s should always be found", ri.CollateralType) // TODO: remove before production
|
||||
continue
|
||||
}
|
||||
|
||||
globalRewardFactor := globalRewardIndex.RewardFactor
|
||||
userRewardFactor := userRewardIndex.RewardFactor
|
||||
@ -748,7 +752,7 @@ func (k Keeper) SimulateHardSynchronization(ctx sdk.Context, claim types.HardLiq
|
||||
fmt.Printf("[LOG]: factor index for %s should always be found", ri.CollateralType) // TODO: remove before production
|
||||
continue
|
||||
}
|
||||
claim.SupplyRewardIndexes[userRewardIndexIndex].RewardIndexes[factorIndex].RewardFactor = globalRewardIndex.RewardFactor
|
||||
claim.BorrowRewardIndexes[userRewardIndexIndex].RewardIndexes[factorIndex].RewardFactor = globalRewardIndex.RewardFactor
|
||||
newRewardsCoin := sdk.NewCoin(userRewardIndex.CollateralType, newRewardsAmount)
|
||||
claim.Reward = claim.Reward.Add(newRewardsCoin)
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -458,6 +458,16 @@ func (mris MultiRewardIndexes) GetRewardIndex(denom string) (MultiRewardIndex, b
|
||||
return MultiRewardIndex{}, false
|
||||
}
|
||||
|
||||
// GetRewardIndexIndex fetches a specific reward index inside the array by its denom
|
||||
func (mris MultiRewardIndexes) GetRewardIndexIndex(denom string) (int, bool) {
|
||||
for i, ri := range mris {
|
||||
if ri.CollateralType == denom {
|
||||
return i, true
|
||||
}
|
||||
}
|
||||
return -1, false
|
||||
}
|
||||
|
||||
// Validate validation for reward indexes
|
||||
func (mris MultiRewardIndexes) Validate() error {
|
||||
for _, mri := range mris {
|
||||
|
Loading…
Reference in New Issue
Block a user