Skip to content

Commit

Permalink
optimize incentive
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsue committed Jan 24, 2025
1 parent c36b442 commit 447f801
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions x/incentive/keeper/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ func (k Keeper) AddDepositReward(ctx sdk.Context, address string, amount sdk.Coi

if len(rewards.Address) == 0 {
rewards.Address = address
rewards.DepositReward = amount
rewards.TotalAmount = amount
} else {
rewards.DepositReward = amount.AddAmount(rewards.DepositReward.Amount)
rewards.TotalAmount = amount.AddAmount(rewards.TotalAmount.Amount)
}

rewards.DepositCount += 1
rewards.DepositReward = amount.AddAmount(rewards.DepositReward.Amount)
rewards.TotalAmount = amount.AddAmount(rewards.TotalAmount.Amount)

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

if len(rewards.Address) == 0 {
rewards.Address = address
rewards.WithdrawReward = amount
rewards.TotalAmount = amount
} else {
rewards.WithdrawReward = amount.AddAmount(rewards.WithdrawReward.Amount)
rewards.TotalAmount = amount.AddAmount(rewards.TotalAmount.Amount)
}

rewards.WithdrawCount += 1
rewards.WithdrawReward = amount.AddAmount(rewards.WithdrawReward.Amount)
rewards.TotalAmount = amount.AddAmount(rewards.TotalAmount.Amount)

k.SetRewards(ctx, rewards)
}
Expand Down Expand Up @@ -91,8 +97,13 @@ func (k Keeper) UpdateRewardStats(ctx sdk.Context, address string, reward sdk.Co
stats.AddressCount += 1
}

if stats.TxCount == 0 {
stats.TotalRewardAmount = reward
} else {
stats.TotalRewardAmount = reward.AddAmount(stats.TotalRewardAmount.Amount)
}

stats.TxCount += 1
stats.TotalRewardAmount = reward.AddAmount(stats.TotalRewardAmount.Amount)

k.SetRewardStats(ctx, stats)
}
Expand Down

0 comments on commit 447f801

Please sign in to comment.