Skip to content

Generic contract for rewards distribution logic #228

@GoldenSylph

Description

@GoldenSylph
  • create a generic StakingRewardsPerEpoch contract (vs the standard StakingRewardsPerBlock)
  • Use baseshare field the synthetix as baseline. the baseshare field has a "multiplier" feature, that we dont need.
  • All rewards contracts follow a similar structure
    • when user performs an action like stake/withdraw his state + global accumulated rewards is updated.
    • in our case, since rewards are not per block, plus they are not in the original staking token, the global accumulator needs to be updated once collectUBI is called and fuse are swapped to G$
  • Because a user might stake just before collectUBI is called, in this case he would get a "free launch" of the rewards accumulated between the two last calls of collectUBI. So we need a little bit more complication
    • when user stake we
      • add the amount to "pendingStakes"
      • we mark that user staked after collectUBI event #X
    • when collectUBI is called
      • we distribute the rewards per share (synthetix rewardPerToken())
      • we then increase number of shares by "pendingStakes" (synthetix totalySupply+pendingStakes)
      • and update an array rewardsPerTokenAt[X+1] with the global rewards (instead of currently it is a single variable)
    • when user does any action - withdraw/stake, we use rewardsPerTokenAt[X+1] as his baseline. so if user staked at time Ti and withdraw at time Tj he is entitled to rewardsPerTokenAt[Tj] - rewardsPerTokenAt[Ti+1] (synthetix earned())

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions