2021-07-15 14:05:54 +00:00
|
|
|
package incentive_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
|
|
|
)
|
|
|
|
|
2021-08-04 14:55:29 +00:00
|
|
|
func (suite *HandlerTestSuite) TestPayoutHardClaimMultiDenom() {
|
2021-07-15 14:05:54 +00:00
|
|
|
userAddr, receiverAddr := suite.addrs[0], suite.addrs[1]
|
|
|
|
|
|
|
|
authBulder := suite.authBuilder().
|
|
|
|
WithSimpleAccount(userAddr, cs(c("bnb", 1e12))).
|
|
|
|
WithSimpleAccount(receiverAddr, nil)
|
|
|
|
|
|
|
|
incentBuilder := suite.incentiveBuilder().
|
2021-08-04 14:55:29 +00:00
|
|
|
WithSimpleSupplyRewardPeriod("bnb", cs(c("hard", 1e6), c("swap", 1e6))).
|
|
|
|
WithSimpleBorrowRewardPeriod("bnb", cs(c("hard", 1e6), c("swap", 1e6)))
|
2021-07-15 14:05:54 +00:00
|
|
|
|
|
|
|
suite.SetupWithGenState(authBulder, incentBuilder)
|
|
|
|
|
|
|
|
// create a deposit and borrow
|
|
|
|
suite.NoError(suite.DeliverHardMsgDeposit(userAddr, cs(c("bnb", 1e11))))
|
|
|
|
suite.NoError(suite.DeliverHardMsgBorrow(userAddr, cs(c("bnb", 1e10))))
|
|
|
|
|
|
|
|
// accumulate some rewards
|
|
|
|
suite.NextBlockAfter(7 * time.Second)
|
|
|
|
|
|
|
|
preClaimBal := suite.GetBalance(userAddr)
|
|
|
|
|
|
|
|
// Check rewards cannot be claimed by vvesting claim msgs
|
|
|
|
err := suite.DeliverIncentiveMsg(
|
2021-08-04 14:55:29 +00:00
|
|
|
types.NewMsgClaimHardRewardVVesting(userAddr, receiverAddr, types.NewSelection("hard", "small"), types.NewSelection("swap", "medium")),
|
2021-07-15 14:05:54 +00:00
|
|
|
)
|
|
|
|
suite.ErrorIs(err, types.ErrInvalidAccountType)
|
|
|
|
|
2021-08-04 14:55:29 +00:00
|
|
|
// Claim denoms
|
2021-07-15 14:05:54 +00:00
|
|
|
err = suite.DeliverIncentiveMsg(
|
2021-08-04 14:55:29 +00:00
|
|
|
types.NewMsgClaimHardReward(userAddr, types.NewSelection("hard", "small"), types.NewSelection("swap", "medium")),
|
2021-07-15 14:05:54 +00:00
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// Check rewards were paid out
|
2021-08-04 14:55:29 +00:00
|
|
|
expectedRewardsHard := c("hard", int64(0.2*float64(2*7*1e6)))
|
|
|
|
expectedRewardsSwap := c("swap", int64(0.5*float64(2*7*1e6)))
|
|
|
|
suite.BalanceEquals(userAddr, preClaimBal.Add(expectedRewardsHard, expectedRewardsSwap))
|
2021-07-15 14:05:54 +00:00
|
|
|
|
|
|
|
suite.VestingPeriodsEqual(userAddr, vesting.Periods{
|
2021-08-04 14:55:29 +00:00
|
|
|
{Length: (17+31)*secondsPerDay - 7, Amount: cs(expectedRewardsHard)},
|
|
|
|
{Length: (28 + 31 + 30 + 31 + 30) * secondsPerDay, Amount: cs(expectedRewardsSwap)}, // second length is stacked on top of the first
|
2021-07-15 14:05:54 +00:00
|
|
|
})
|
|
|
|
// Check that claimed coins have been removed from a claim's reward
|
|
|
|
suite.HardRewardEquals(userAddr, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *HandlerTestSuite) TestPayoutHardClaimSingleDenom() {
|
|
|
|
userAddr := suite.addrs[0]
|
|
|
|
|
|
|
|
authBulder := suite.authBuilder().
|
|
|
|
WithSimpleAccount(userAddr, cs(c("bnb", 1e12)))
|
|
|
|
|
|
|
|
incentBuilder := suite.incentiveBuilder().
|
|
|
|
WithSimpleSupplyRewardPeriod("bnb", cs(c("hard", 1e6), c("swap", 1e6))).
|
|
|
|
WithSimpleBorrowRewardPeriod("bnb", cs(c("hard", 1e6), c("swap", 1e6)))
|
|
|
|
|
|
|
|
suite.SetupWithGenState(authBulder, incentBuilder)
|
|
|
|
|
|
|
|
// create a deposit and borrow
|
|
|
|
suite.NoError(suite.DeliverHardMsgDeposit(userAddr, cs(c("bnb", 1e11))))
|
|
|
|
suite.NoError(suite.DeliverHardMsgBorrow(userAddr, cs(c("bnb", 1e10))))
|
|
|
|
|
|
|
|
// accumulate some rewards
|
|
|
|
suite.NextBlockAfter(7 * time.Second)
|
|
|
|
|
|
|
|
preClaimBal := suite.GetBalance(userAddr)
|
|
|
|
|
|
|
|
// Check rewards cannot be claimed by vvesting claim msgs
|
|
|
|
err := suite.DeliverIncentiveMsg(
|
2021-08-04 14:55:29 +00:00
|
|
|
types.NewMsgClaimHardRewardVVesting(userAddr, suite.addrs[1], types.NewSelection("swap", "large")),
|
2021-07-15 14:05:54 +00:00
|
|
|
)
|
|
|
|
suite.ErrorIs(err, types.ErrInvalidAccountType)
|
|
|
|
|
|
|
|
// Claim rewards
|
|
|
|
err = suite.DeliverIncentiveMsg(
|
2021-08-04 14:55:29 +00:00
|
|
|
types.NewMsgClaimHardReward(userAddr, types.NewSelection("swap", "large")),
|
2021-07-15 14:05:54 +00:00
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// Check rewards were paid out
|
|
|
|
expectedRewards := c("swap", 2*7*1e6)
|
|
|
|
suite.BalanceEquals(userAddr, preClaimBal.Add(expectedRewards))
|
|
|
|
|
|
|
|
suite.VestingPeriodsEqual(userAddr, vesting.Periods{
|
2021-08-04 14:55:29 +00:00
|
|
|
{Length: (17+31+28+31+30+31+30+31+31+30+31+30+31)*secondsPerDay - 7, Amount: cs(expectedRewards)},
|
2021-07-15 14:05:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Check that claimed coins have been removed from a claim's reward
|
|
|
|
suite.HardRewardEquals(userAddr, cs(c("hard", 2*7*1e6)))
|
|
|
|
}
|
|
|
|
|
2021-08-04 14:55:29 +00:00
|
|
|
func (suite *HandlerTestSuite) TestPayoutHardClaimVVestingMultiDenom() {
|
2021-07-15 14:05:54 +00:00
|
|
|
valAddr, receiverAddr := suite.addrs[0], suite.addrs[1]
|
|
|
|
|
|
|
|
vva := suite.NewValidatorVestingAccountWithBalance(valAddr, cs(c("bnb", 1e12)))
|
|
|
|
|
|
|
|
authBulder := suite.authBuilder().
|
|
|
|
WithAccounts(vva).
|
|
|
|
WithSimpleAccount(receiverAddr, nil)
|
|
|
|
|
|
|
|
incentBuilder := suite.incentiveBuilder().
|
2021-08-04 14:55:29 +00:00
|
|
|
WithSimpleSupplyRewardPeriod("bnb", cs(c("hard", 1e6), c("swap", 1e6))).
|
|
|
|
WithSimpleBorrowRewardPeriod("bnb", cs(c("hard", 1e6), c("swap", 1e6)))
|
2021-07-15 14:05:54 +00:00
|
|
|
|
|
|
|
suite.SetupWithGenState(authBulder, incentBuilder)
|
|
|
|
|
|
|
|
// create a deposit and borrow
|
|
|
|
suite.NoError(suite.DeliverHardMsgDeposit(valAddr, cs(c("bnb", 1e11))))
|
|
|
|
suite.NoError(suite.DeliverHardMsgBorrow(valAddr, cs(c("bnb", 1e10))))
|
|
|
|
|
|
|
|
// accumulate some rewards
|
|
|
|
suite.NextBlockAfter(7 * time.Second)
|
|
|
|
|
|
|
|
preClaimBal := suite.GetBalance(receiverAddr)
|
|
|
|
|
|
|
|
// Check rewards cannot be claimed by normal claim msgs
|
|
|
|
err := suite.DeliverIncentiveMsg(
|
2021-08-04 14:55:29 +00:00
|
|
|
types.NewMsgClaimHardReward(valAddr, types.NewSelection("hard", "small"), types.NewSelection("swap", "medium")),
|
2021-07-15 14:05:54 +00:00
|
|
|
)
|
|
|
|
suite.ErrorIs(err, types.ErrInvalidAccountType)
|
|
|
|
|
|
|
|
// Claim rewards
|
|
|
|
err = suite.DeliverIncentiveMsg(
|
2021-08-04 14:55:29 +00:00
|
|
|
types.NewMsgClaimHardRewardVVesting(valAddr, receiverAddr, types.NewSelection("hard", "small"), types.NewSelection("swap", "medium")),
|
2021-07-15 14:05:54 +00:00
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// Check rewards were paid out
|
2021-08-04 14:55:29 +00:00
|
|
|
expectedRewardsHard := c("hard", int64(0.2*float64(2*7*1e6)))
|
|
|
|
expectedRewardsSwap := c("swap", int64(0.5*float64(2*7*1e6)))
|
|
|
|
suite.BalanceEquals(receiverAddr, preClaimBal.Add(expectedRewardsHard, expectedRewardsSwap))
|
2021-07-15 14:05:54 +00:00
|
|
|
|
|
|
|
suite.VestingPeriodsEqual(receiverAddr, vesting.Periods{
|
2021-08-04 14:55:29 +00:00
|
|
|
{Length: (17+31)*secondsPerDay - 7, Amount: cs(expectedRewardsHard)},
|
|
|
|
{Length: (28 + 31 + 30 + 31 + 30) * secondsPerDay, Amount: cs(expectedRewardsSwap)}, // second length is stacked on top of the first
|
2021-07-15 14:05:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Check that each claim reward coin's amount has been reset to 0
|
|
|
|
suite.HardRewardEquals(valAddr, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *HandlerTestSuite) TestPayoutHardClaimVVestingSingleDenom() {
|
|
|
|
valAddr, receiverAddr := suite.addrs[0], suite.addrs[1]
|
|
|
|
|
|
|
|
vva := suite.NewValidatorVestingAccountWithBalance(valAddr, cs(c("bnb", 1e12)))
|
|
|
|
|
|
|
|
authBulder := suite.authBuilder().
|
|
|
|
WithAccounts(vva).
|
|
|
|
WithSimpleAccount(receiverAddr, nil)
|
|
|
|
|
|
|
|
incentBuilder := suite.incentiveBuilder().
|
|
|
|
WithSimpleSupplyRewardPeriod("bnb", cs(c("hard", 1e6), c("swap", 1e6))).
|
|
|
|
WithSimpleBorrowRewardPeriod("bnb", cs(c("hard", 1e6), c("swap", 1e6)))
|
|
|
|
|
|
|
|
suite.SetupWithGenState(authBulder, incentBuilder)
|
|
|
|
|
|
|
|
// create a deposit and borrow
|
|
|
|
suite.NoError(suite.DeliverHardMsgDeposit(valAddr, cs(c("bnb", 1e11))))
|
|
|
|
suite.NoError(suite.DeliverHardMsgBorrow(valAddr, cs(c("bnb", 1e10))))
|
|
|
|
|
|
|
|
// accumulate some rewards
|
|
|
|
suite.NextBlockAfter(7 * time.Second)
|
|
|
|
|
|
|
|
preClaimBal := suite.GetBalance(receiverAddr)
|
|
|
|
|
|
|
|
// Check rewards cannot be claimed by normal claim msgs
|
|
|
|
err := suite.DeliverIncentiveMsg(
|
2021-08-04 14:55:29 +00:00
|
|
|
types.NewMsgClaimHardReward(valAddr, types.NewSelection("swap", "large")),
|
2021-07-15 14:05:54 +00:00
|
|
|
)
|
|
|
|
suite.ErrorIs(err, types.ErrInvalidAccountType)
|
|
|
|
|
|
|
|
// Claim rewards
|
|
|
|
err = suite.DeliverIncentiveMsg(
|
2021-08-04 14:55:29 +00:00
|
|
|
types.NewMsgClaimHardRewardVVesting(valAddr, receiverAddr, types.NewSelection("swap", "large")),
|
2021-07-15 14:05:54 +00:00
|
|
|
)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
|
|
|
// Check rewards were paid out
|
|
|
|
expectedRewards := c("swap", 2*7*1e6)
|
|
|
|
suite.BalanceEquals(receiverAddr, preClaimBal.Add(expectedRewards))
|
|
|
|
|
|
|
|
suite.VestingPeriodsEqual(receiverAddr, vesting.Periods{
|
2021-08-04 14:55:29 +00:00
|
|
|
{Length: (17+31+28+31+30+31+30+31+31+30+31+30+31)*secondsPerDay - 7, Amount: cs(expectedRewards)},
|
2021-07-15 14:05:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Check that claimed coins have been removed from a claim's reward
|
|
|
|
suite.HardRewardEquals(valAddr, cs(c("hard", 2*7*1e6)))
|
|
|
|
}
|