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

Add minor comment for superfluid reward distr #1104

Merged
merged 9 commits into from
Mar 30, 2022
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Add two validator delegator
  • Loading branch information
mattverse committed Mar 18, 2022

Verified

This commit was signed with the committer’s verified signature.
Robbepop Robin Freyler
commit f8e3707ecf6284528792100fefa397e5b83c1af7
51 changes: 33 additions & 18 deletions x/superfluid/keeper/hooks_test.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() {
validatorStats []stakingtypes.BondStatus
delegatorNumber int
superDelegations []superfluidDelegation
expRewards sdk.Coins
expRewards []sdk.Coins
}{
{
"happy path with single validator and delegator",
@@ -20,11 +20,24 @@ func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() {
[]superfluidDelegation{{0, 0, 0, 1000000}},
// bond denom staked in pool = 15_000_000
// with risk adjustment, the actual bond denom staked via superfluid would be 15_000_000 * (1 - 0.5) = 7_500_000
// we do a arbitrary swap to set spot price, which adjusts superfluid staked equivilent base denom 20_000_000 * (1 - 0.5) = 10_000_000 during begin block
// we do an arbitrary swap to set spot price, which adjusts superfluid staked equivilent base denom 20_000_000 * (1 - 0.5) = 10_000_000 during begin block
// delegation rewards are calculated using the equation (current period cumulative reward ratio - last period cumulative reward ratio) * asset amount
// in this test case, the calculation for expected reward would be the following (0.99999 - 0) * 10_000_000
// thus we expect 999_990 stake as rewards
sdk.Coins{{Amount: sdk.NewInt(999990), Denom: "stake"}},
[]sdk.Coins{{sdk.NewCoin("stake", sdk.NewInt(999990))}},
},
{
"happy path with two validator and delegator each",
[]stakingtypes.BondStatus{stakingtypes.Bonded, stakingtypes.Bonded},
2,
[]superfluidDelegation{{0, 0, 0, 1000000}, {1, 1, 0, 1000000}},
// reward for the first block propser / lock 0 that has been superfluid staked would be equivilent to calculations done above
// 999_990 stake as rewards.
// reward for the second delegation is expected to be different. Amount superfluid staked would be equivilently 7_500_000 stake.
// This would be the first block propsed by the second validator, current period cumulative reward ratio being 999_86.66684,
// last period cumulative reward ratio being 0
// Thus as rewards, we expect 999986stake, calculted using the following equation: (999_86.66684 - 0) * 7_500_000
[]sdk.Coins{{sdk.NewCoin("stake", sdk.NewInt(999990))}, {sdk.NewCoin("stake", sdk.NewInt(999986))}},
},
}

@@ -47,24 +60,26 @@ func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() {
suite.SwapAndSetSpotPrice(poolIds[0], poolAssets[1], poolAssets[0])

// run epoch actions
suite.BeginNewBlock(true, valAddrs[0])
// run begin block for each validator so that both validator gets block rewards
for _, valAddr := range valAddrs {
suite.BeginNewBlock(true, valAddr)
}

// check lptoken twap value set
newEpochMultiplier := suite.App.SuperfluidKeeper.GetOsmoEquivalentMultiplier(suite.Ctx, denoms[0])
suite.Require().Equal(newEpochMultiplier, sdk.NewDec(15))

// check gauge creation in new block
intermediaryAccAddr := suite.App.SuperfluidKeeper.GetLockIdIntermediaryAccountConnection(suite.Ctx, locks[0].ID)
intermediaryAcc := suite.App.SuperfluidKeeper.GetIntermediaryAccount(suite.Ctx, intermediaryAccAddr)
gauge, err := suite.App.IncentivesKeeper.GetGaugeByID(suite.Ctx, intermediaryAcc.GaugeId)

suite.Require().NoError(err)
suite.Require().Equal(gauge.Id, intermediaryAcc.GaugeId)
suite.Require().Equal(gauge.IsPerpetual, true)
suite.Require().Equal(gauge.Coins, tc.expRewards)
suite.Require().Equal(gauge.NumEpochsPaidOver, uint64(1))
suite.Require().Equal(gauge.FilledEpochs, uint64(1))
suite.Require().Equal(gauge.DistributedCoins, tc.expRewards)
for index, lock := range locks {
// check gauge creation in new block
intermediaryAccAddr := suite.App.SuperfluidKeeper.GetLockIdIntermediaryAccountConnection(suite.Ctx, lock.ID)
intermediaryAcc := suite.App.SuperfluidKeeper.GetIntermediaryAccount(suite.Ctx, intermediaryAccAddr)
gauge, err := suite.App.IncentivesKeeper.GetGaugeByID(suite.Ctx, intermediaryAcc.GaugeId)
suite.Require().NoError(err)
suite.Require().Equal(gauge.Id, intermediaryAcc.GaugeId)
suite.Require().Equal(gauge.IsPerpetual, true)
suite.Require().Equal(gauge.Coins, tc.expRewards[index])
suite.Require().Equal(gauge.DistributedCoins, tc.expRewards[index])
}

// check delegation changes
for _, acc := range intermediaryAccs {
@@ -74,8 +89,8 @@ func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() {
suite.Require().True(found)
suite.Require().Equal(sdk.NewDec(7500000), delegation.Shares)
}
balance := suite.App.BankKeeper.GetAllBalances(suite.Ctx, delAddrs[0])
suite.Require().Equal(tc.expRewards, balance)
//balance := suite.App.BankKeeper.GetAllBalances(suite.Ctx, delAddrs[0])
//suite.Require().Equal(tc.expRewards, balance)
mattverse marked this conversation as resolved.
Show resolved Hide resolved
})
}
}