diff --git a/x/alliance/keeper/reward.go b/x/alliance/keeper/reward.go index 0ef9a536..41cf7bd9 100644 --- a/x/alliance/keeper/reward.go +++ b/x/alliance/keeper/reward.go @@ -131,10 +131,15 @@ func accumulateRewards(latestRewardHistories types.RewardHistories, rewardHistor // To calculate the number of rewards claimable, take reward_history * alliance_token_amount * reward_weight func (k Keeper) AddAssetsToRewardPool(ctx sdk.Context, from sdk.AccAddress, val types.AllianceValidator, coins sdk.Coins) error { rewardHistories := types.NewRewardHistories(val.GlobalRewardHistory) + // We need some delegations before we can split rewards. Else rewards belong to no one and do nothing + if len(val.TotalDelegatorShares) == 0 { + return nil + } + totalAssetWeight := k.totalAssetWeight(ctx, val) - // We need some delegations before we can split rewards. Else rewards belong to no one if totalAssetWeight.IsZero() { - return types.ErrZeroDelegations + // Do nothing since there are no assets to distribute rewards to + return nil } for _, c := range coins { diff --git a/x/alliance/keeper/tests/reward_test.go b/x/alliance/keeper/tests/reward_test.go index 3d14b9e5..b45db4c7 100644 --- a/x/alliance/keeper/tests/reward_test.go +++ b/x/alliance/keeper/tests/reward_test.go @@ -62,10 +62,6 @@ func TestRewardPoolAndGlobalIndex(t *testing.T) { coin := app.BankKeeper.GetBalance(ctx, mintPoolAddr, "stake") require.Equal(t, sdk.NewCoin("stake", sdk.NewInt(4000_000)), coin) - // Transfer to reward pool without delegations will fail - err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000_000)))) - require.Error(t, err) - _, err = app.AllianceKeeper.Delegate(ctx, user1, val1, sdk.NewCoin(AllianceDenom, sdk.NewInt(1000_000))) require.NoError(t, err) assets := app.AllianceKeeper.GetAllAssets(ctx)