From 2943e5411497f101d19a8b23d9edf616c013ac0b Mon Sep 17 00:00:00 2001 From: javiersuweijie Date: Tue, 27 Feb 2024 22:46:11 +0800 Subject: [PATCH] fix: reward calculation for different types of token --- docs/proto/proto-docs.md | 1 + proto/alliance/alliance/params.proto | 1 + x/alliance/keeper/asset.go | 18 - x/alliance/keeper/reward.go | 70 ++-- x/alliance/keeper/tests/grpc_query_test.go | 2 +- x/alliance/keeper/tests/reward_test.go | 435 ++++++++++++++++++--- x/alliance/types/alliance.go | 3 +- x/alliance/types/params.go | 15 +- x/alliance/types/params.pb.go | 114 ++++-- 9 files changed, 531 insertions(+), 128 deletions(-) diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index d3c06e38..c8c94d98 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -133,6 +133,7 @@ | ----- | ---- | ----- | ----------- | | `denom` | [string](#string) | | | | `index` | [string](#string) | | | +| `alliance` | [string](#string) | | | diff --git a/proto/alliance/alliance/params.proto b/proto/alliance/alliance/params.proto index 74fe2d68..13bc57ec 100644 --- a/proto/alliance/alliance/params.proto +++ b/proto/alliance/alliance/params.proto @@ -34,4 +34,5 @@ message RewardHistory { (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; + string alliance = 3; } \ No newline at end of file diff --git a/x/alliance/keeper/asset.go b/x/alliance/keeper/asset.go index 121a64ef..dfd54483 100644 --- a/x/alliance/keeper/asset.go +++ b/x/alliance/keeper/asset.go @@ -28,15 +28,6 @@ func (k Keeper) InitializeAllianceAssets(ctx context.Context, assets []*types.Al continue } asset.IsInitialized = true - err = k.IterateAllianceValidatorInfo(ctx, func(valAddr sdk.ValAddress, info types.AllianceValidatorInfo) bool { - if err = k.CreateInitialRewardWeightChangeSnapshot(ctx, asset.Denom, valAddr, info); err != nil { - return true - } - return false - }) - if err != nil { - return err - } if err = k.SetAsset(ctx, *asset); err != nil { return err } @@ -387,15 +378,6 @@ func (k Keeper) SetRewardWeightChangeSnapshot(ctx context.Context, asset types.A return k.setRewardWeightChangeSnapshot(ctx, asset.Denom, valAddr, uint64(sdkCtx.BlockHeight()), snapshot) } -func (k Keeper) CreateInitialRewardWeightChangeSnapshot(ctx context.Context, denom string, valAddr sdk.ValAddress, info types.AllianceValidatorInfo) error { - snapshot := types.RewardWeightChangeSnapshot{ - PrevRewardWeight: cmath.LegacyZeroDec(), - RewardHistories: info.GlobalRewardHistory, - } - sdkCtx := sdk.UnwrapSDKContext(ctx) - return k.setRewardWeightChangeSnapshot(ctx, denom, valAddr, uint64(sdkCtx.BlockHeight()), snapshot) -} - func (k Keeper) setRewardWeightChangeSnapshot(ctx context.Context, denom string, valAddr sdk.ValAddress, height uint64, snapshot types.RewardWeightChangeSnapshot) error { key := types.GetRewardWeightChangeSnapshotKey(denom, valAddr, height) store := k.storeService.OpenKVStore(ctx) diff --git a/x/alliance/keeper/reward.go b/x/alliance/keeper/reward.go index 3bb00c66..efa33ebd 100644 --- a/x/alliance/keeper/reward.go +++ b/x/alliance/keeper/reward.go @@ -103,9 +103,9 @@ func (k Keeper) ClaimDelegationRewards( // It takes past reward_rate changes into account by using the RewardRateChangeSnapshot entry func (k Keeper) CalculateDelegationRewards(ctx context.Context, delegation types.Delegation, val types.AllianceValidator, asset types.AllianceAsset) (sdk.Coins, types.RewardHistories, error) { totalRewards := sdk.NewCoins() - currentRewardHistory := types.NewRewardHistories(val.GlobalRewardHistory) - delegationRewardHistories := types.NewRewardHistories(delegation.RewardHistory) + currentRewardHistory := types.NewRewardHistories(val.GlobalRewardHistory).GetIndexByAlliance(asset.Denom) + delegationRewardHistories := types.NewRewardHistories(delegation.RewardHistory).GetIndexByAlliance(asset.Denom) valAddr, err := sdk.ValAddressFromBech32(val.OperatorAddress) if err != nil { return nil, nil, err @@ -136,15 +136,22 @@ func accumulateRewards(latestRewardHistories types.RewardHistories, rewardHistor delegationTokens := math.LegacyNewDecFromInt(types.GetDelegationTokens(delegation, validator, asset).Amount) for _, history := range latestRewardHistories { - rewardHistory, found := rewardHistories.GetIndexByDenom(history.Denom) + rewardHistory, found := rewardHistories.GetIndexByDenom(history.Denom, history.Alliance) if !found { rewardHistory.Denom = history.Denom rewardHistory.Index = math.LegacyZeroDec() + rewardHistory.Alliance = history.Alliance } if rewardHistory.Index.GTE(history.Index) { continue } - claimWeight := delegationTokens.Mul(rewardWeight) + var claimWeight math.LegacyDec + // Handle legacy reward history that does not have a specific alliance + if rewardHistory.Alliance == "" { + claimWeight = delegationTokens.Mul(rewardWeight) + } else { + claimWeight = delegationTokens + } totalClaimable := (history.Index.Sub(rewardHistory.Index)).Mul(claimWeight) rewardHistory.Index = history.Index rewards = rewards.Add(sdk.NewCoin(history.Denom, totalClaimable.TruncateInt())) @@ -163,22 +170,35 @@ func (k Keeper) AddAssetsToRewardPool(ctx context.Context, from sdk.AccAddress, if len(val.TotalDelegatorShares) == 0 { return nil } + alliances := k.GetAllAssets(ctx) - totalAssetWeight := k.totalAssetWeight(ctx, val) - if totalAssetWeight.IsZero() { - // Do nothing since there are no assets to distribute rewards to - return nil + // Get total reward weight to normalize weights + totalRewardWeight := math.LegacyZeroDec() + for _, asset := range alliances { + if shouldSkipRewardsToAsset(ctx, *asset, val) { + continue + } + totalRewardWeight = totalRewardWeight.Add(asset.RewardWeight) } - for _, c := range coins { - rewardHistory, found := rewardHistories.GetIndexByDenom(c.Denom) - if !found { - rewardHistories = append(rewardHistories, types.RewardHistory{ - Denom: c.Denom, - Index: math.LegacyNewDecFromInt(c.Amount).Quo(totalAssetWeight), - }) - } else { - rewardHistory.Index = rewardHistory.Index.Add(math.LegacyNewDecFromInt(c.Amount).Quo(totalAssetWeight)) + for _, asset := range alliances { + if shouldSkipRewardsToAsset(ctx, *asset, val) { + continue + } + normalizedWeight := asset.RewardWeight.Quo(totalRewardWeight) + for _, c := range coins { + rewardHistory, found := rewardHistories.GetIndexByDenom(c.Denom, asset.Denom) + totalTokens := val.TotalTokensWithAsset(*asset) + difference := math.LegacyNewDecFromInt(c.Amount).Mul(normalizedWeight).Quo(totalTokens) + if !found { + rewardHistories = append(rewardHistories, types.RewardHistory{ + Denom: c.Denom, + Alliance: asset.Denom, + Index: difference, + }) + } else { + rewardHistory.Index = rewardHistory.Index.Add(difference) + } } } @@ -189,19 +209,7 @@ func (k Keeper) AddAssetsToRewardPool(ctx context.Context, from sdk.AccAddress, return k.bankKeeper.SendCoinsFromAccountToModule(ctx, from, types.RewardsPoolName, coins) } -func (k Keeper) totalAssetWeight(ctx context.Context, val types.AllianceValidator) math.LegacyDec { - total := math.LegacyZeroDec() +func shouldSkipRewardsToAsset(ctx context.Context, asset types.AllianceAsset, val types.AllianceValidator) bool { sdkCtx := sdk.UnwrapSDKContext(ctx) - for _, token := range val.TotalDelegatorShares { - asset, found := k.GetAssetByDenom(ctx, token.Denom) - if !found { - continue - } - if !asset.RewardsStarted(sdkCtx.BlockTime()) { - continue - } - totalValTokens := val.TotalTokensWithAsset(asset) - total = total.Add(asset.RewardWeight.Mul(totalValTokens)) - } - return total + return asset.TotalTokens.IsZero() || !asset.RewardsStarted(sdkCtx.BlockTime()) || val.TotalTokensWithAsset(asset).IsZero() } diff --git a/x/alliance/keeper/tests/grpc_query_test.go b/x/alliance/keeper/tests/grpc_query_test.go index e7ca02af..64866cb3 100644 --- a/x/alliance/keeper/tests/grpc_query_test.go +++ b/x/alliance/keeper/tests/grpc_query_test.go @@ -324,7 +324,7 @@ func TestClaimQueryReward(t *testing.T) { Rewards: []sdk.Coin{ { Denom: ULunaAlliance, - Amount: math.NewInt(32666), + Amount: math.NewInt(32665), }, }, }, queryDelegation) diff --git a/x/alliance/keeper/tests/reward_test.go b/x/alliance/keeper/tests/reward_test.go index af16c3ca..895a04d2 100644 --- a/x/alliance/keeper/tests/reward_test.go +++ b/x/alliance/keeper/tests/reward_test.go @@ -58,12 +58,12 @@ func TestRewardPoolAndGlobalIndex(t *testing.T) { user2 := addrs[1] // Mint tokens - err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(4000_000)))) + err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(5000_000)))) require.NoError(t, err) - err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake2", math.NewInt(4000_000)))) + err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake2", math.NewInt(5000_000)))) require.NoError(t, err) coin := app.BankKeeper.GetBalance(ctx, mintPoolAddr, "stake") - require.Equal(t, sdk.NewCoin("stake", math.NewInt(4000_000)), coin) + require.Equal(t, sdk.NewCoin("stake", math.NewInt(5000_000)), coin) _, err = app.AllianceKeeper.Delegate(ctx, user1, val1, sdk.NewCoin(AllianceDenom, math.NewInt(1000_000))) require.NoError(t, err) @@ -84,8 +84,9 @@ func TestRewardPoolAndGlobalIndex(t *testing.T) { globalIndices := types.NewRewardHistories(val1.GlobalRewardHistory) require.Equal(t, types.RewardHistories{ types.RewardHistory{ - Denom: "stake", - Index: math.LegacyNewDec(1), + Denom: "stake", + Index: math.LegacyNewDec(2), + Alliance: AllianceDenom, }, }, globalIndices) @@ -97,32 +98,49 @@ func TestRewardPoolAndGlobalIndex(t *testing.T) { require.NoError(t, err) // Transfer to reward pool - err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(2000_000)))) + err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(2_400_000)))) require.NoError(t, err) globalIndices = types.NewRewardHistories(val1.GlobalRewardHistory) require.Equal(t, types.RewardHistories{ types.RewardHistory{ - Denom: "stake", - Index: math.LegacyNewDec(14).Quo(math.LegacyNewDec(12)), + Denom: "stake", + Alliance: AllianceDenom, + Index: math.LegacyMustNewDecFromStr("2.400000000000000001"), + }, + types.RewardHistory{ + Denom: "stake", + Alliance: AllianceDenomTwo, + Index: math.LegacyMustNewDecFromStr("1.999999999999999999"), }, }, globalIndices) // Transfer another token to reward pool - err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake2", math.NewInt(4000_000)))) + err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake2", math.NewInt(1_200_000)))) require.NoError(t, err) // Expect global index to be updated - // 14/12 + 4/12 = 18/12 globalIndices = types.NewRewardHistories(val1.GlobalRewardHistory) require.Equal(t, types.RewardHistories{ types.RewardHistory{ - Denom: "stake", - Index: math.LegacyNewDec(14).Quo(math.LegacyNewDec(12)), + Denom: "stake", + Alliance: AllianceDenom, + Index: math.LegacyMustNewDecFromStr("2.400000000000000001"), + }, + types.RewardHistory{ + Denom: "stake", + Alliance: AllianceDenomTwo, + Index: math.LegacyMustNewDecFromStr("1.999999999999999999"), }, types.RewardHistory{ - Denom: "stake2", - Index: math.LegacyNewDec(4).Quo(math.LegacyNewDec(12)), + Denom: "stake2", + Alliance: AllianceDenom, + Index: math.LegacyMustNewDecFromStr("0.2"), + }, + types.RewardHistory{ + Denom: "stake2", + Alliance: AllianceDenomTwo, + Index: math.LegacyMustNewDecFromStr("1.0"), }, }, globalIndices) } @@ -133,7 +151,7 @@ func TestClaimRewards(t *testing.T) { Params: types.DefaultParams(), Assets: []types.AllianceAsset{ types.NewAllianceAsset(AllianceDenom, math.LegacyNewDec(2), math.LegacyNewDec(0), math.LegacyNewDec(5), math.LegacyNewDec(0), ctx.BlockTime()), - types.NewAllianceAsset(AllianceDenomTwo, math.LegacyNewDec(10), math.LegacyNewDec(2), math.LegacyNewDec(12), math.LegacyNewDec(0), ctx.BlockTime()), + types.NewAllianceAsset(AllianceDenomTwo, math.LegacyNewDec(8), math.LegacyNewDec(2), math.LegacyNewDec(12), math.LegacyNewDec(0), ctx.BlockTime()), }, }) @@ -154,9 +172,9 @@ func TestClaimRewards(t *testing.T) { user2 := addrs[1] // Mint tokens - err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(4000_000)))) + err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(5000_000)))) require.NoError(t, err) - err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake2", math.NewInt(4000_000)))) + err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake2", math.NewInt(5000_000)))) require.NoError(t, err) // New delegation from user 1 @@ -167,7 +185,7 @@ func TestClaimRewards(t *testing.T) { require.NoError(t, err) // Transfer to reward pool - err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(2000_000)))) + err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000_000)))) require.NoError(t, err) // New delegation from user 2 @@ -178,7 +196,7 @@ func TestClaimRewards(t *testing.T) { require.NoError(t, err) // Transfer to reward pool - err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(2000_000)))) + err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000_000)))) require.NoError(t, err) asset, _ := app.AllianceKeeper.GetAssetByDenom(ctx, AllianceDenom) @@ -200,12 +218,24 @@ func TestClaimRewards(t *testing.T) { require.Equal(t, types.NewRewardHistories([]types.RewardHistory{ { - Denom: "stake", - Index: math.LegacyMustNewDecFromStr("1.166666666666666667"), + Denom: "stake", + Index: math.LegacyMustNewDecFromStr("1.2"), + Alliance: AllianceDenom, + }, + { + Denom: "stake", + Index: math.LegacyMustNewDecFromStr("0.8"), + Alliance: AllianceDenomTwo, }, { - Denom: "stake2", - Index: math.LegacyMustNewDecFromStr("0.333333333333333333"), + Denom: "stake2", + Index: math.LegacyMustNewDecFromStr("0.8"), + Alliance: AllianceDenom, + }, + { + Denom: "stake2", + Index: math.LegacyMustNewDecFromStr("3.2"), + Alliance: AllianceDenomTwo, }, }), types.NewRewardHistories(val1.GlobalRewardHistory), @@ -214,33 +244,33 @@ func TestClaimRewards(t *testing.T) { // before claiming, there should be tokens in rewards pool coins := app.BankKeeper.GetAllBalances(ctx, rewardsPoolAddr) require.Equal(t, - sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(4000_000)), sdk.NewCoin("stake2", math.NewInt(4000_000))), + sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(2000_000)), sdk.NewCoin("stake2", math.NewInt(4000_000))), coins, ) // User 1 claims rewards - // User 1 has 1 STAKE (2 Power) - // Added 2 stake rewards (fully belonging to user 1) - // User 2 has 1 STAKE (10 Power) - // Added 2 stake rewards (user1: 2/12 * 2, user2: 10/12 * 2) - // Added 4 stake2 rewards (user1: 2/12 * 4, user2: 10/12 * 4) + // user 1 got full rewards for the first reward (stake) + // + 20% of the second deposit (stake) + // + 20% of the three deposits (stake2) coins, err = app.AllianceKeeper.ClaimDelegationRewards(ctx, user1, val1, AllianceDenom) require.NoError(t, err) - require.Equal(t, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(2_333_333)), sdk.NewCoin("stake2", math.NewInt(666_666))), coins) + require.Equal(t, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1_200_000)), sdk.NewCoin("stake2", math.NewInt(800_000))), coins) // User 2 claims rewards but doesn't use the right denom _, err = app.AllianceKeeper.ClaimDelegationRewards(ctx, user2, val1, AllianceDenom) require.Error(t, err) // User 2 claims rewards + // user 2 got 80% of the second deposit (stake) + // + 80% of the three deposits (stake2) coins, err = app.AllianceKeeper.ClaimDelegationRewards(ctx, user2, val1, AllianceDenomTwo) require.NoError(t, err) - require.Equal(t, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1_666_666)), sdk.NewCoin("stake2", math.NewInt(3_333_333))), coins) + require.Equal(t, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(800_000)), sdk.NewCoin("stake2", math.NewInt(3_200_000))), coins) // After claiming, there should be nothing left in rewards pool // Some rounding left coins = app.BankKeeper.GetAllBalances(ctx, rewardsPoolAddr) - require.Equal(t, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1)), sdk.NewCoin("stake2", math.NewInt(1))), coins) + require.Equal(t, sdk.NewCoins(), coins) // Global indices require.NoError(t, err) @@ -249,11 +279,11 @@ func TestClaimRewards(t *testing.T) { // Check that all delegations have updated local indices delegation, found := app.AllianceKeeper.GetDelegation(ctx, user1, valAddr1, AllianceDenom) require.True(t, found) - require.Equal(t, indices, types.NewRewardHistories(delegation.RewardHistory)) + require.Equal(t, indices.GetIndexByAlliance(AllianceDenom), types.NewRewardHistories(delegation.RewardHistory)) delegation, found = app.AllianceKeeper.GetDelegation(ctx, user2, valAddr1, AllianceDenomTwo) require.True(t, found) - require.Equal(t, indices, types.NewRewardHistories(delegation.RewardHistory)) + require.Equal(t, indices.GetIndexByAlliance(AllianceDenomTwo), types.NewRewardHistories(delegation.RewardHistory)) } func TestClaimRewardsBeforeRewardsIssuance(t *testing.T) { @@ -263,7 +293,7 @@ func TestClaimRewardsBeforeRewardsIssuance(t *testing.T) { Params: types.DefaultParams(), Assets: []types.AllianceAsset{ types.NewAllianceAsset(AllianceDenom, math.LegacyNewDec(2), math.LegacyNewDec(0), math.LegacyNewDec(5), math.LegacyNewDec(0), ctx.BlockTime().Add(-time.Hour)), - types.NewAllianceAsset(AllianceDenomTwo, math.LegacyNewDec(10), math.LegacyNewDec(2), math.LegacyNewDec(12), math.LegacyNewDec(0), ctx.BlockTime().Add(time.Hour)), + types.NewAllianceAsset(AllianceDenomTwo, math.LegacyNewDec(8), math.LegacyNewDec(2), math.LegacyNewDec(12), math.LegacyNewDec(0), ctx.BlockTime().Add(time.Hour)), }, }) queryServer := keeper.NewQueryServerImpl(app.AllianceKeeper) @@ -377,7 +407,7 @@ func TestClaimRewardsWithMultipleValidators(t *testing.T) { Params: types.DefaultParams(), Assets: []types.AllianceAsset{ types.NewAllianceAsset(AllianceDenom, math.LegacyNewDec(2), math.LegacyNewDec(0), math.LegacyNewDec(5), math.LegacyNewDec(0), ctx.BlockTime()), - types.NewAllianceAsset(AllianceDenomTwo, math.LegacyNewDec(10), math.LegacyNewDec(2), math.LegacyNewDec(12), math.LegacyNewDec(0), ctx.BlockTime()), + types.NewAllianceAsset(AllianceDenomTwo, math.LegacyNewDec(8), math.LegacyNewDec(2), math.LegacyNewDec(12), math.LegacyNewDec(0), ctx.BlockTime()), }, }) @@ -391,7 +421,7 @@ func TestClaimRewardsWithMultipleValidators(t *testing.T) { // Accounts addrs := test_helpers.AddTestAddrsIncremental(app, ctx, 4, sdk.NewCoins( sdk.NewCoin(AllianceDenom, math.NewInt(1000_000)), - sdk.NewCoin(AllianceDenomTwo, math.NewInt(1000_000)), + sdk.NewCoin(AllianceDenomTwo, math.NewInt(10_000_000)), )) pks := test_helpers.CreateTestPubKeys(2) @@ -436,7 +466,7 @@ func TestClaimRewardsWithMultipleValidators(t *testing.T) { // New delegation from user 2 to val 2 val2, _ := app.AllianceKeeper.GetAllianceValidator(ctx, valAddr2) - _, err = app.AllianceKeeper.Delegate(ctx, user2, val2, sdk.NewCoin(AllianceDenomTwo, math.NewInt(1000_000))) + _, err = app.AllianceKeeper.Delegate(ctx, user2, val2, sdk.NewCoin(AllianceDenomTwo, math.NewInt(10_000_000))) require.NoError(t, err) assets := app.AllianceKeeper.GetAllAssets(ctx) @@ -445,10 +475,10 @@ func TestClaimRewardsWithMultipleValidators(t *testing.T) { // Check total bonded amount totalBonded, err := app.StakingKeeper.TotalBondedTokens(ctx) require.NoError(t, err) - require.Equal(t, math.NewInt(13_000_000), totalBonded) + require.Equal(t, math.NewInt(11_000_000), totalBonded) // Transfer to rewards to fee pool to be distributed - err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, authtypes.FeeCollectorName, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(4000_000)))) + err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, authtypes.FeeCollectorName, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(4_000_000)))) require.NoError(t, err) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) @@ -456,7 +486,7 @@ func TestClaimRewardsWithMultipleValidators(t *testing.T) { // At the next begin block, tokens will be distributed from the fee pool cons1, _ := val1.GetConsAddr() cons2, _ := val2.GetConsAddr() - var votingPower int64 = 12 + var votingPower int64 = 10 err = app.DistrKeeper.AllocateTokens(ctx, votingPower, []abcitypes.VoteInfo{ { Validator: abcitypes.Validator{ @@ -467,7 +497,7 @@ func TestClaimRewardsWithMultipleValidators(t *testing.T) { { Validator: abcitypes.Validator{ Address: cons2, - Power: 10, + Power: 8, }, }, }) @@ -478,11 +508,11 @@ func TestClaimRewardsWithMultipleValidators(t *testing.T) { require.Equal(t, math.NewInt(0), commission.Commission.AmountOf("stake").TruncateInt()) commission, err = app.DistrKeeper.GetValidatorAccumulatedCommission(ctx, getOperator(val2)) require.NoError(t, err) - require.Equal(t, math.NewInt(3333333), commission.Commission.AmountOf("stake").TruncateInt()) + require.Equal(t, math.NewInt(3200_000), commission.Commission.AmountOf("stake").TruncateInt()) rewards, err := app.DistrKeeper.GetValidatorCurrentRewards(ctx, getOperator(val1)) require.NoError(t, err) - require.Equal(t, math.NewInt(666666), rewards.Rewards.AmountOf("stake").TruncateInt()) + require.Equal(t, math.NewInt(800_000), rewards.Rewards.AmountOf("stake").TruncateInt()) rewards, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, getOperator(val2)) require.NoError(t, err) require.Equal(t, math.NewInt(0), rewards.Rewards.AmountOf("stake").TruncateInt()) @@ -490,7 +520,7 @@ func TestClaimRewardsWithMultipleValidators(t *testing.T) { // User 1 should be getting all the rewards from validator 1 since it has 0 commission coins, err := app.AllianceKeeper.ClaimDelegationRewards(ctx, user1, val1, AllianceDenom) require.NoError(t, err) - require.Equal(t, math.NewInt(666666), coins.AmountOf("stake")) + require.Equal(t, math.NewInt(800_000), coins.AmountOf("stake")) // User 2 should be getting no rewards since validator 2 has 100% commission coins, err = app.AllianceKeeper.ClaimDelegationRewards(ctx, user2, val2, AllianceDenomTwo) @@ -995,3 +1025,318 @@ func TestRewardWeightWithZeroTokens(t *testing.T) { require.Equal(t, beforeMintPoolAmount, afterMintPoolAmount) } + +func TestClaimRewardsWithDifferentTokenDecimals(t *testing.T) { + app, ctx := createTestContext(t) + app.AllianceKeeper.InitGenesis(ctx, &types.GenesisState{ + Params: types.DefaultParams(), + Assets: []types.AllianceAsset{ + types.NewAllianceAsset(AllianceDenom, math.LegacyNewDec(2), math.LegacyNewDec(0), math.LegacyNewDec(5), math.LegacyNewDec(0), ctx.BlockTime()), + types.NewAllianceAsset(AllianceDenomTwo, math.LegacyNewDec(2), math.LegacyNewDec(0), math.LegacyNewDec(5), math.LegacyNewDec(0), ctx.BlockTime()), + }, + }) + + // Accounts + mintPoolAddr := app.AccountKeeper.GetModuleAddress(minttypes.ModuleName) + rewardsPoolAddr := app.AccountKeeper.GetModuleAddress(types.RewardsPoolName) + delegations, err := app.StakingKeeper.GetAllDelegations(ctx) + require.NoError(t, err) + valAddr1, err := sdk.ValAddressFromBech32(delegations[0].ValidatorAddress) + require.NoError(t, err) + val1, err := app.AllianceKeeper.GetAllianceValidator(ctx, valAddr1) + require.NoError(t, err) + addrs := test_helpers.AddTestAddrsIncremental(app, ctx, 2, sdk.NewCoins( + sdk.NewCoin(AllianceDenom, math.NewInt(1000_000)), + sdk.NewCoin(AllianceDenomTwo, math.NewInt(100_000_000)), + )) + user1 := addrs[0] + user2 := addrs[1] + + // Mint tokens + err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(4000_000)))) + require.NoError(t, err) + err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin("stake2", math.NewInt(4000_000)))) + require.NoError(t, err) + + // New delegation from user 1 + _, err = app.AllianceKeeper.Delegate(ctx, user1, val1, sdk.NewCoin(AllianceDenom, math.NewInt(1000_000))) + require.NoError(t, err) + assets := app.AllianceKeeper.GetAllAssets(ctx) + err = app.AllianceKeeper.RebalanceBondTokenWeights(ctx, assets) + require.NoError(t, err) + + // New delegation from user 2 + _, err = app.AllianceKeeper.Delegate(ctx, user2, val1, sdk.NewCoin(AllianceDenomTwo, math.NewInt(100_000_000))) + require.NoError(t, err) + assets = app.AllianceKeeper.GetAllAssets(ctx) + err = app.AllianceKeeper.RebalanceBondTokenWeights(ctx, assets) + require.NoError(t, err) + + // Transfer to reward pool + err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(2000_000)))) + require.NoError(t, err) + + // User 1 claims rewards + coins, err := app.AllianceKeeper.ClaimDelegationRewards(ctx, user1, val1, AllianceDenom) + require.NoError(t, err) + require.Equal(t, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000_000))), coins) + + // User 2 claims rewards + coins, err = app.AllianceKeeper.ClaimDelegationRewards(ctx, user2, val1, AllianceDenomTwo) + require.NoError(t, err) + require.Equal(t, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000_000))), coins) + + // After claiming, there should be nothing left in rewards pool + // Some rounding left + coins = app.BankKeeper.GetAllBalances(ctx, rewardsPoolAddr) + require.Equal(t, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(0))), coins) +} + +// Since 0.3.4, rewards distribution logic has changed to be asset scoped +// this test makes sure that we have backward compatibility +func TestMigratedRewardsWithRatesChange(t *testing.T) { + var err error + app, ctx := createTestContext(t) + ctx = ctx.WithBlockHeight(1) + app.AllianceKeeper.InitGenesis(ctx, &types.GenesisState{ + Params: types.DefaultParams(), + Assets: []types.AllianceAsset{ + types.NewAllianceAsset(AllianceDenom, math.LegacyNewDec(2), math.LegacyNewDec(0), math.LegacyNewDec(5), math.LegacyNewDec(0), ctx.BlockTime()), + types.NewAllianceAsset(AllianceDenomTwo, math.LegacyNewDec(8), math.LegacyNewDec(2), math.LegacyNewDec(12), math.LegacyNewDec(0), ctx.BlockTime()), + }, + }) + + // Set tax and rewards to be zero for easier calculation + distParams, err := app.DistrKeeper.Params.Get(ctx) + require.NoError(t, err) + distParams.CommunityTax = math.LegacyZeroDec() + err = app.DistrKeeper.Params.Set(ctx, distParams) + require.NoError(t, err) + + // Accounts + mintPoolAddr := app.AccountKeeper.GetModuleAddress(minttypes.ModuleName) + bondDenom, err := app.StakingKeeper.BondDenom(ctx) + require.NoError(t, err) + addrs := test_helpers.AddTestAddrsIncremental(app, ctx, 4, sdk.NewCoins( + sdk.NewCoin(AllianceDenom, math.NewInt(10_000_000)), + sdk.NewCoin(AllianceDenomTwo, math.NewInt(10_000_000)), + )) + + // Creating validator 0% commissions + pks := test_helpers.CreateTestPubKeys(2) + valAddr1 := sdk.ValAddress(addrs[0]) + _val1 := teststaking.NewValidator(t, valAddr1, pks[0]) + _val1.Commission = stakingtypes.Commission{ + CommissionRates: stakingtypes.CommissionRates{ + Rate: math.LegacyNewDec(0), + MaxRate: math.LegacyNewDec(0), + MaxChangeRate: math.LegacyNewDec(0), + }, + UpdateTime: time.Now(), + } + test_helpers.RegisterNewValidator(t, app, ctx, _val1) + val1, err := app.AllianceKeeper.GetAllianceValidator(ctx, valAddr1) + require.NoError(t, err) + + user1 := addrs[2] + user2 := addrs[3] + + // Mint bond denom + err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(40_000_000)))) + require.NoError(t, err) + + // New delegations + _, err = app.AllianceKeeper.Delegate(ctx, user1, val1, sdk.NewCoin(AllianceDenom, math.NewInt(1_000_000))) + require.NoError(t, err) + _, err = app.AllianceKeeper.Delegate(ctx, user2, val1, sdk.NewCoin(AllianceDenomTwo, math.NewInt(1_000_000))) + require.NoError(t, err) + + assets := app.AllianceKeeper.GetAllAssets(ctx) + err = app.AllianceKeeper.RebalanceBondTokenWeights(ctx, assets) + require.NoError(t, err) + + // Manually update global asset history + val1.GlobalRewardHistory = append(val1.GlobalRewardHistory, types.RewardHistory{ + Denom: bondDenom, + Index: math.LegacyMustNewDecFromStr("0.5"), + Alliance: "", + }) + err = app.AllianceKeeper.SetValidator(ctx, val1) + require.NoError(t, err) + err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, types.RewardsPoolName, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(5_000_000)))) + require.NoError(t, err) + + // Check rewards for user1 + queryServer := keeper.NewQueryServerImpl(app.AllianceKeeper) + qCtx, _ := ctx.CacheContext() + rewards, err := queryServer.AllianceDelegationRewards(qCtx, &types.QueryAllianceDelegationRewardsRequest{ + DelegatorAddr: user1.String(), + ValidatorAddr: val1.GetOperator(), + Denom: AllianceDenom, + Pagination: nil, + }) + require.NoError(t, err) + require.Equal(t, math.NewInt(1_000_000), sdk.NewCoins(rewards.Rewards...).AmountOf(bondDenom)) + + err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(10_000_000)))) + require.NoError(t, err) + + // Update alliance asset reward weight + err = app.AllianceKeeper.UpdateAllianceAsset(ctx, types.NewAllianceAsset(AllianceDenom, math.LegacyNewDec(8), math.LegacyNewDec(2), math.LegacyNewDec(12), math.LegacyNewDec(0), ctx.BlockTime())) + require.NoError(t, err) + assets = app.AllianceKeeper.GetAllAssets(ctx) + err = app.AllianceKeeper.RebalanceBondTokenWeights(ctx, assets) + require.NoError(t, err) + + err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(10_000_000)))) + require.NoError(t, err) + + rewards1, err := app.AllianceKeeper.ClaimDelegationRewards(ctx, user1, val1, AllianceDenom) + require.NoError(t, err) + require.Equal(t, math.NewInt(1_000_000+2_000_000+5_000_000), rewards1.AmountOf(bondDenom)) + + rewards2, err := app.AllianceKeeper.ClaimDelegationRewards(ctx, user2, val1, AllianceDenomTwo) + require.NoError(t, err) + require.Equal(t, math.NewInt(4_000_000+8_000_000+5_000_000), rewards2.AmountOf(bondDenom)) +} + +func TestMigratedRewards(t *testing.T) { + var err error + app, ctx := createTestContext(t) + ctx = ctx.WithBlockHeight(1) + app.AllianceKeeper.InitGenesis(ctx, &types.GenesisState{ + Params: types.DefaultParams(), + Assets: []types.AllianceAsset{ + types.NewAllianceAsset(AllianceDenom, math.LegacyNewDec(2), math.LegacyNewDec(0), math.LegacyNewDec(5), math.LegacyNewDec(0), ctx.BlockTime()), + types.NewAllianceAsset(AllianceDenomTwo, math.LegacyNewDec(8), math.LegacyNewDec(2), math.LegacyNewDec(12), math.LegacyNewDec(0), ctx.BlockTime()), + }, + }) + + // Set tax and rewards to be zero for easier calculation + distParams, err := app.DistrKeeper.Params.Get(ctx) + require.NoError(t, err) + distParams.CommunityTax = math.LegacyZeroDec() + err = app.DistrKeeper.Params.Set(ctx, distParams) + require.NoError(t, err) + + // Accounts + mintPoolAddr := app.AccountKeeper.GetModuleAddress(minttypes.ModuleName) + bondDenom, err := app.StakingKeeper.BondDenom(ctx) + require.NoError(t, err) + addrs := test_helpers.AddTestAddrsIncremental(app, ctx, 4, sdk.NewCoins( + sdk.NewCoin(AllianceDenom, math.NewInt(10_000_000)), + sdk.NewCoin(AllianceDenomTwo, math.NewInt(10_000_000)), + )) + + pks := test_helpers.CreateTestPubKeys(2) + + // Creating two validators with 0% commission + valAddr1 := sdk.ValAddress(addrs[0]) + _val1 := teststaking.NewValidator(t, valAddr1, pks[0]) + _val1.Commission = stakingtypes.Commission{ + CommissionRates: stakingtypes.CommissionRates{ + Rate: math.LegacyNewDec(0), + MaxRate: math.LegacyNewDec(0), + MaxChangeRate: math.LegacyNewDec(0), + }, + UpdateTime: time.Now(), + } + test_helpers.RegisterNewValidator(t, app, ctx, _val1) + + valAddr2 := sdk.ValAddress(addrs[1]) + _val2 := teststaking.NewValidator(t, valAddr2, pks[1]) + _val2.Commission = stakingtypes.Commission{ + CommissionRates: stakingtypes.CommissionRates{ + Rate: math.LegacyNewDec(0), + MaxRate: math.LegacyNewDec(0), + MaxChangeRate: math.LegacyNewDec(0), + }, + UpdateTime: time.Now(), + } + test_helpers.RegisterNewValidator(t, app, ctx, _val2) + + val1, _ := app.AllianceKeeper.GetAllianceValidator(ctx, valAddr1) + val2, _ := app.AllianceKeeper.GetAllianceValidator(ctx, valAddr2) + + user1 := addrs[2] + user2 := addrs[3] + + // Mint bond denom + err = app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(40_000_000)))) + require.NoError(t, err) + + // New delegations + _, err = app.AllianceKeeper.Delegate(ctx, user1, val1, sdk.NewCoin(AllianceDenom, math.NewInt(1000_000))) + require.NoError(t, err) + _, err = app.AllianceKeeper.Delegate(ctx, user2, val1, sdk.NewCoin(AllianceDenomTwo, math.NewInt(1000_000))) + require.NoError(t, err) + _, err = app.AllianceKeeper.Delegate(ctx, user1, val2, sdk.NewCoin(AllianceDenomTwo, math.NewInt(1000_000))) + require.NoError(t, err) + _, err = app.AllianceKeeper.Delegate(ctx, user2, val2, sdk.NewCoin(AllianceDenomTwo, math.NewInt(1000_000))) + require.NoError(t, err) + + assets := app.AllianceKeeper.GetAllAssets(ctx) + err = app.AllianceKeeper.RebalanceBondTokenWeights(ctx, assets) + require.NoError(t, err) + + // Manually update global asset history + val1.GlobalRewardHistory = append(val1.GlobalRewardHistory, + types.RewardHistory{ + Denom: bondDenom, + Index: math.LegacyMustNewDecFromStr("0.5"), + Alliance: "", + }, + ) + err = app.AllianceKeeper.SetValidator(ctx, val1) + require.NoError(t, err) + + val2.GlobalRewardHistory = append(val2.GlobalRewardHistory, + types.RewardHistory{ + Denom: bondDenom, + Index: math.LegacyMustNewDecFromStr("0.5"), + Alliance: "", + }, + ) + err = app.AllianceKeeper.SetValidator(ctx, val2) + require.NoError(t, err) + err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, types.RewardsPoolName, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(13_000_000)))) + require.NoError(t, err) + + err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(10_000_000)))) + require.NoError(t, err) + err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val2, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(10_000_000)))) + require.NoError(t, err) + + rewards1, err := app.AllianceKeeper.ClaimDelegationRewards(ctx, user1, val1, AllianceDenom) + require.NoError(t, err) + require.Equal(t, math.NewInt(1_000_000+2_000_000), rewards1.AmountOf(bondDenom)) + + rewards2, err := app.AllianceKeeper.ClaimDelegationRewards(ctx, user2, val1, AllianceDenomTwo) + require.NoError(t, err) + require.Equal(t, math.NewInt(4_000_000+8_000_000), rewards2.AmountOf(bondDenom)) + + rewards3, err := app.AllianceKeeper.ClaimDelegationRewards(ctx, user1, val2, AllianceDenomTwo) + require.NoError(t, err) + require.Equal(t, math.NewInt(4_000_000+5_000_000-1), rewards3.AmountOf(bondDenom)) + + rewards4, err := app.AllianceKeeper.ClaimDelegationRewards(ctx, user2, val2, AllianceDenomTwo) + require.NoError(t, err) + require.Equal(t, math.NewInt(4_000_000+5_000_000-1), rewards4.AmountOf(bondDenom)) + + // Make sure nothing left to claim + rewards1, err = app.AllianceKeeper.ClaimDelegationRewards(ctx, user1, val1, AllianceDenom) + require.NoError(t, err) + require.Equal(t, math.NewInt(0), rewards1.AmountOf(bondDenom)) + + rewards2, err = app.AllianceKeeper.ClaimDelegationRewards(ctx, user2, val1, AllianceDenomTwo) + require.NoError(t, err) + require.Equal(t, math.NewInt(0), rewards2.AmountOf(bondDenom)) + + rewards3, err = app.AllianceKeeper.ClaimDelegationRewards(ctx, user1, val2, AllianceDenomTwo) + require.NoError(t, err) + require.Equal(t, math.NewInt(0), rewards3.AmountOf(bondDenom)) + + rewards4, err = app.AllianceKeeper.ClaimDelegationRewards(ctx, user2, val2, AllianceDenomTwo) + require.NoError(t, err) + require.Equal(t, math.NewInt(0), rewards4.AmountOf(bondDenom)) +} diff --git a/x/alliance/types/alliance.go b/x/alliance/types/alliance.go index f5db14b5..edcc2be0 100644 --- a/x/alliance/types/alliance.go +++ b/x/alliance/types/alliance.go @@ -1,8 +1,9 @@ package types func NewRewardWeightChangeSnapshot(asset AllianceAsset, val AllianceValidator) RewardWeightChangeSnapshot { + assetRewardHistory := RewardHistories(val.GlobalRewardHistory).GetIndexByAlliance(asset.Denom) return RewardWeightChangeSnapshot{ PrevRewardWeight: asset.RewardWeight, - RewardHistories: val.GlobalRewardHistory, + RewardHistories: assetRewardHistory, } } diff --git a/x/alliance/types/params.go b/x/alliance/types/params.go index 34faa563..c9f74de6 100644 --- a/x/alliance/types/params.go +++ b/x/alliance/types/params.go @@ -70,9 +70,20 @@ func NewRewardHistories(r []RewardHistory) RewardHistories { return r } -func (r RewardHistories) GetIndexByDenom(denom string) (ri *RewardHistory, found bool) { +func (r RewardHistories) GetIndexByAlliance(alliance string) (ris RewardHistories) { + for _, rh := range r { + // If alliance is empty, it means it was the legacy reward history that does not have a specific alliance + // Used to handle the old implementation of reward history + if rh.Alliance == alliance || rh.Alliance == "" { + ris = append(ris, rh) + } + } + return ris +} + +func (r RewardHistories) GetIndexByDenom(denom string, alliance string) (ri *RewardHistory, found bool) { idx := slices.IndexFunc(r, func(e RewardHistory) bool { - return e.Denom == denom + return e.Denom == denom && e.Alliance == alliance }) if idx < 0 { return &RewardHistory{}, false diff --git a/x/alliance/types/params.pb.go b/x/alliance/types/params.pb.go index 420c63b4..d9bcfc37 100644 --- a/x/alliance/types/params.pb.go +++ b/x/alliance/types/params.pb.go @@ -93,8 +93,9 @@ func (m *Params) GetLastTakeRateClaimTime() time.Time { } type RewardHistory struct { - Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` - Index cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=index,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"index"` + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` + Index cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=index,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"index"` + Alliance string `protobuf:"bytes,3,opt,name=alliance,proto3" json:"alliance,omitempty"` } func (m *RewardHistory) Reset() { *m = RewardHistory{} } @@ -137,6 +138,13 @@ func (m *RewardHistory) GetDenom() string { return "" } +func (m *RewardHistory) GetAlliance() string { + if m != nil { + return m.Alliance + } + return "" +} + func init() { proto.RegisterType((*Params)(nil), "alliance.alliance.Params") proto.RegisterType((*RewardHistory)(nil), "alliance.alliance.RewardHistory") @@ -145,34 +153,34 @@ func init() { func init() { proto.RegisterFile("alliance/alliance/params.proto", fileDescriptor_245e75f0d2ae44fd) } var fileDescriptor_245e75f0d2ae44fd = []byte{ - // 417 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x8a, 0xd4, 0x40, - 0x10, 0xc6, 0x93, 0xd5, 0x5d, 0xdc, 0x16, 0x91, 0x0d, 0x2b, 0xcc, 0x8c, 0xd0, 0x91, 0x3d, 0x79, - 0xd9, 0x8e, 0x7f, 0x6e, 0x1e, 0xc7, 0x80, 0x7f, 0x10, 0x94, 0x30, 0x27, 0x11, 0x43, 0x4d, 0x52, - 0x66, 0x9b, 0x4d, 0xa7, 0x43, 0x77, 0x8f, 0x6e,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a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcd, 0x6e, 0xd4, 0x30, + 0x10, 0xc7, 0xd7, 0x85, 0x56, 0x5d, 0x23, 0x84, 0x1a, 0x15, 0x69, 0x77, 0x91, 0x1c, 0xd4, 0x13, + 0x97, 0x3a, 0x7c, 0xdc, 0x38, 0x2e, 0x2b, 0xf1, 0x21, 0x24, 0x50, 0xb4, 0x27, 0x84, 0x88, 0x66, + 0x93, 0x21, 0xb5, 0x1a, 0xc7, 0x91, 0xed, 0x85, 0xe6, 0x2d, 0xf6, 0xc8, 0x05, 0x89, 0x87, 0xe0, + 0x21, 0x7a, 0xac, 0x38, 0x21, 0x0e, 0x05, 0xed, 0x5e, 0x78, 0x0c, 0x64, 0x3b, 0x69, 0x51, 0xb9, + 0x70, 0x9b, 0xf1, 0x7f, 0xe6, 0x37, 0xf3, 0xb7, 0x4d, 0x19, 0x54, 0x95, 0x80, 0x3a, 0xc7, 0xe4, + 0x22, 0x68, 0x40, 0x83, 0x34, 0xbc, 0xd1, 0xca, 0xaa, 0x68, 0xaf, 0x3f, 0xe6, 0x7d, 0x30, 0xd9, + 0x2f, 0x55, 0xa9, 0xbc, 0x9a, 0xb8, 0x28, 0x14, 0x4e, 0xc6, 0xb9, 0x32, 0x52, 0x99, 0x2c, 0x08, + 0x21, 0xe9, 0x24, 0x56, 0x2a, 0x55, 0x56, 0x98, 0xf8, 0x6c, 0xb1, 0x7c, 0x9f, 0x14, 0x4b, 0x0d, + 0x56, 0xa8, 0xba, 0xd3, 0xe3, 0xab, 0xba, 0x15, 0x12, 0x8d, 0x05, 0xd9, 0x84, 0x82, 0x83, 0xcf, + 0x5b, 0x74, 0xe7, 0xb5, 0xdf, 0x2a, 0x7a, 0x45, 0xf7, 0x34, 0x7e, 0x04, 0x5d, 0x64, 0x05, 0x56, + 0xd0, 0x66, 0xae, 0x74, 0x44, 0xee, 0x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 0xd2, 0xf4, 0xc5, 0xe9, 0x9a, 0x91, + 0xb3, 0x35, 0x23, 0xbf, 0xd6, 0x8c, 0xac, 0x36, 0x6c, 0x70, 0xb6, 0x61, 0x83, 0xef, 0x1b, 0x36, + 0x78, 0x73, 0xbf, 0x14, 0xf6, 0x68, 0xb9, 0xe0, 0xb9, 0x92, 0x89, 0x45, 0xad, 0xe1, 0x50, 0xaa, + 0x1a, 0xdb, 0xcb, 0xff, 0x77, 0x72, 0x19, 0xda, 0xb6, 0x41, 0xb3, 0xd8, 0xf1, 0x37, 0xf3, 0xe8, + 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7c, 0x2b, 0xe9, 0x6d, 0xac, 0x02, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -230,6 +238,9 @@ func (this *RewardHistory) Equal(that interface{}) bool { if !this.Index.Equal(that1.Index) { return false } + if this.Alliance != that1.Alliance { + return false + } return true } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -299,6 +310,13 @@ func (m *RewardHistory) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Alliance) > 0 { + i -= len(m.Alliance) + copy(dAtA[i:], m.Alliance) + i = encodeVarintParams(dAtA, i, uint64(len(m.Alliance))) + i-- + dAtA[i] = 0x1a + } { size := m.Index.Size() i -= size @@ -357,6 +375,10 @@ func (m *RewardHistory) Size() (n int) { } l = m.Index.Size() n += 1 + l + sovParams(uint64(l)) + l = len(m.Alliance) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } return n } @@ -610,6 +632,38 @@ func (m *RewardHistory) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Alliance", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Alliance = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:])