Skip to content

Function "bondedTargetRewardUnlock" returns wrong values in the wrong range #10

@ghost

Description

What's the issue?

You communicated that rewards are locked for either 6 months or until 80% of the network is staked. The bonded ratio starts at 80% and should decrease by 1% each week (so after e.g. 8 weeks it should be at ~72%).

Current Implementation

This function should return values from 80 down to 0. What it actually does is returning values from 100 down to 0.

function bondedTargetRewardUnlock() public view returns (uint256) {
  uint256 passedTime = block.timestamp.sub(unbondingStartDate());
  uint256 passedPercents = PERCENT_UNIT.mul(passedTime).div(unbondingPeriod()); // total duration from 0% to 100% is unbondingPeriod
  if (passedPercents > PERCENT_UNIT) {
    return 0;
  }
  return PERCENT_UNIT - passedPercents;
}

New implementation

So I'd suggest the following changes:

function bondedTargetStart() public pure returns (uint256) {
  return 80;
}

// ...

function bondedTargetRewardUnlock() public view returns (uint256) {
  uint256 passedTime = block.timestamp.sub(unbondingStartDate());
  uint256 passedPercents = PERCENT_UNIT.mul(passedTime).div(unbondingPeriod());
  if (passedPercents > bondedTargetStart()) {
    // Limit passed percents to bondedTargetStart() as this is the maximum value
    passedPercents = bondedTargetStart();
  }
  return bondedTargetStart() - passedPercents;
}

Metadata

Metadata

Assignees

No one assigned

    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