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

Extract Common Reward Calculation Logic into p/reward Package #478

Open
notJoon opened this issue Jan 21, 2025 · 0 comments · May be fixed by #480
Open

Extract Common Reward Calculation Logic into p/reward Package #478

notJoon opened this issue Jan 21, 2025 · 0 comments · May be fixed by #480
Assignees

Comments

@notJoon
Copy link
Member

notJoon commented Jan 21, 2025

Description

Background

Currently, we have similar reward calculation logic implemented in both the launchpad and gov/staker packages. This leads to code duplication and potential maintenance issues. We should extract the common functionality into a shared reward package to improve code reusability and maintainability.

Proposed Solution

Create a new reward package that contains the common reward calculation logic. This package will provide base structures and interfaces that can be extended by both the launchpad and staker packages for their specific needs.

Key Components

  1. Common Structures:

    • RewardInfo: Base structure for storing staking and reward information
    • RewardCalculator: Interface defining core reward calculation methods
    • BaseRewardState: Base structure for managing reward state
  2. Functions to be Extracted:

Function Name Move To Notes
AddStake reward.BaseRewardState Core staking logic
RemoveStake reward.BaseRewardState Core unstaking logic
CalculateReward reward.BaseRewardState Basic reward calculation
Info reward.BaseRewardState Renamed to GetRewardInfo
PriceAccumulationUint64 reward.BaseRewardState Helper function
finalize/UpdateRewards reward.BaseRewardState Renamed to UpdateRewards
  1. Package-Specific Extensions:

Launchpad-specific:

type LaunchpadRewardState struct {
    *reward.BaseRewardState
    EndHeight        uint64
    RewardPerBlock   *u256.Uint
    TotalEmptyBlock  uint64
}

Staker-specific:

type StakerRewardState struct {
    *reward.BaseRewardState
    ProtocolFeePriceAccumulation  map[string]*u256.Uint
    CurrentProtocolFeeBalance     map[string]uint64
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant