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

Implement and test an Identity earning power calculator #104

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/calculators/IdentityEarningPowerCalculator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.23;

import {IEarningPowerCalculator} from "src/interfaces/IEarningPowerCalculator.sol";

/// @title IdentityEarningPowerCalculator
/// @author [ScopeLift](https://scopelift.co)
/// @notice A simple earning power calculator that maps earning power directly to staked amount in
/// a 1:1 ratio. This implementation is suitable when all stakers should earn rewards proportional
/// to their stake without any adjustments or weights.
///
/// The calculator does not modify earning power based on the staker or delegatee, and is never
/// qualified for bumping since the earning power calculation is a pure identity function of the
/// staked amount.
contract IdentityEarningPowerCalculator is IEarningPowerCalculator {
/// @notice Returns earning power equal to the staked amount.
/// @param _amountStaked The amount of tokens staked.
/// @return The earning power, equal to _amountStaked.
function getEarningPower(uint256 _amountStaked, address, /* _staker */ address /* _delegatee */ )
external
pure
returns (uint256)
{
return _amountStaked;
}

/// @notice Returns earning power equal to the staked amount and always indicates no
/// qualification for bumping.
/// @param _amountStaked The amount of tokens staked.
/// @return The earning power value, equal to _amountStaked.
/// @return Always false since this implementation never qualifies for bumping.
function getNewEarningPower(
uint256 _amountStaked,
address, /* _staker */
address, /* _delegatee */
uint256 /* _oldEarningPower */
) external pure returns (uint256, bool) {
return (_amountStaked, false);
}
}
2 changes: 1 addition & 1 deletion test/BinaryEligibilityOracleEarningPowerCalculator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Test, console2} from "forge-std/Test.sol";
import {
BinaryEligibilityOracleEarningPowerCalculator as EarningPowerCalculator,
Ownable
} from "src/BinaryEligibilityOracleEarningPowerCalculator.sol";
} from "src/calculators/BinaryEligibilityOracleEarningPowerCalculator.sol";

contract EarningPowerCalculatorTest is Test {
address public owner;
Expand Down
37 changes: 37 additions & 0 deletions test/IdentityEarningPowerCalculator.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.23;

import {Test} from "forge-std/Test.sol";
import {IdentityEarningPowerCalculator} from "src/calculators/IdentityEarningPowerCalculator.sol";

contract IdentityEarningPowerCalculatorTest is Test {
IdentityEarningPowerCalculator calculator;

function setUp() public {
calculator = new IdentityEarningPowerCalculator();
}
}

contract GetEarningPower is IdentityEarningPowerCalculatorTest {
function testFuzz_ReturnsAmountStaked(uint256 _amountStaked, address _staker, address _delegatee)
public
view
{
assertEq(calculator.getEarningPower(_amountStaked, _staker, _delegatee), _amountStaked);
}
}

contract GetNewEarningPower is IdentityEarningPowerCalculatorTest {
function testFuzz_ReturnsAmountStakedAndNeverQualifiesForBump(
uint256 _amountStaked,
address _staker,
address _delegatee,
uint256 _oldEarningPower
) public view {
(uint256 _earningPower, bool _isQualifiedForUpdate) =
calculator.getNewEarningPower(_amountStaked, _staker, _delegatee, _oldEarningPower);

assertEq(_earningPower, _amountStaked);
assertEq(_isQualifiedForUpdate, false);
}
}
Loading