Skip to content

Commit 447f801

Browse files
committed
optimize incentive
1 parent c36b442 commit 447f801

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

x/incentive/keeper/reward.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ func (k Keeper) AddDepositReward(ctx sdk.Context, address string, amount sdk.Coi
3939

4040
if len(rewards.Address) == 0 {
4141
rewards.Address = address
42+
rewards.DepositReward = amount
43+
rewards.TotalAmount = amount
44+
} else {
45+
rewards.DepositReward = amount.AddAmount(rewards.DepositReward.Amount)
46+
rewards.TotalAmount = amount.AddAmount(rewards.TotalAmount.Amount)
4247
}
4348

4449
rewards.DepositCount += 1
45-
rewards.DepositReward = amount.AddAmount(rewards.DepositReward.Amount)
46-
rewards.TotalAmount = amount.AddAmount(rewards.TotalAmount.Amount)
4750

4851
k.SetRewards(ctx, rewards)
4952
}
@@ -54,11 +57,14 @@ func (k Keeper) AddWithdrawReward(ctx sdk.Context, address string, amount sdk.Co
5457

5558
if len(rewards.Address) == 0 {
5659
rewards.Address = address
60+
rewards.WithdrawReward = amount
61+
rewards.TotalAmount = amount
62+
} else {
63+
rewards.WithdrawReward = amount.AddAmount(rewards.WithdrawReward.Amount)
64+
rewards.TotalAmount = amount.AddAmount(rewards.TotalAmount.Amount)
5765
}
5866

5967
rewards.WithdrawCount += 1
60-
rewards.WithdrawReward = amount.AddAmount(rewards.WithdrawReward.Amount)
61-
rewards.TotalAmount = amount.AddAmount(rewards.TotalAmount.Amount)
6268

6369
k.SetRewards(ctx, rewards)
6470
}
@@ -91,8 +97,13 @@ func (k Keeper) UpdateRewardStats(ctx sdk.Context, address string, reward sdk.Co
9197
stats.AddressCount += 1
9298
}
9399

100+
if stats.TxCount == 0 {
101+
stats.TotalRewardAmount = reward
102+
} else {
103+
stats.TotalRewardAmount = reward.AddAmount(stats.TotalRewardAmount.Amount)
104+
}
105+
94106
stats.TxCount += 1
95-
stats.TotalRewardAmount = reward.AddAmount(stats.TotalRewardAmount.Amount)
96107

97108
k.SetRewardStats(ctx, stats)
98109
}

0 commit comments

Comments
 (0)