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

Improve getNewEarningPower logic #43

Closed
garyghayrat opened this issue Oct 9, 2024 · 1 comment · Fixed by #64
Closed

Improve getNewEarningPower logic #43

garyghayrat opened this issue Oct 9, 2024 · 1 comment · Fixed by #64
Labels
calculator Tasks related to earning power calculator & oracle pre-audit Needed before the audit deadline todo Issues that need to be tackled pre-audit

Comments

@garyghayrat
Copy link
Collaborator

          We should make an issue to think abou this: right now the logic for the earning power calculation is duplicated in this method, and in the `getNewEarningPower` method, where it is intermingled with the qualification status boolean logic as well. There's probably a slightly cleaner way to implement this, but no need to bikeshed in this PR.

Originally posted by @apbendi in #24 (comment)

@garyghayrat garyghayrat added todo Issues that need to be tackled pre-audit pre-audit Needed before the audit deadline calculator Tasks related to earning power calculator & oracle labels Oct 9, 2024
@garyghayrat
Copy link
Collaborator Author

How about something like:

function getEarningPower(uint256 _amountStaked, address, /* _staker */ address _delegatee)
    external
    view
    returns (uint256)
{
    if (isOracleStale()) {
        return _amountStaked;
    }

    return isDelegateeEligible(_delegatee) ? _amountStaked : 0;
}

function getNewEarningPower(
    uint256 _amountStaked,
    address, /* _staker */
    address _delegatee,
    uint256 /* _oldEarningPower */
) external view returns (uint256, bool) {
    if (isOracleStale()) {
        return (_amountStaked, true);
    }

    if (!isDelegateeEligible(_delegatee)) {
        bool isUpdateDelayElapsed = (timeOfIneligibility[_delegatee] + updateEligibilityDelay) <= block.timestamp;
        return (0, isUpdateDelayElapsed);
    }

    return (_amountStaked, true);
}

function isOracleStale() internal view returns (bool) {
    return block.timestamp - lastOracleUpdateTime > STALE_ORACLE_WINDOW;
}

function isDelegateeEligible(address _delegatee) internal view returns (bool) {
    return delegateeScores[_delegatee] >= delegateeEligibilityThresholdScore;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
calculator Tasks related to earning power calculator & oracle pre-audit Needed before the audit deadline todo Issues that need to be tackled pre-audit
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant