Skip to content

Commit

Permalink
add getLifetimeRewards()
Browse files Browse the repository at this point in the history
  • Loading branch information
pblivin0x committed Jul 3, 2024
1 parent 61b8409 commit 9d80f09
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/interfaces/staking/ISnapshotStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ interface ISnapshotStakingPool is IERC20 {
/// @return The total pool reward at the time `snapshotId`
function rewardAt(uint256 snapshotId) external view returns (uint256);

/// @notice Retrieves the rewards across all snapshots for `account`.
/// @param account The account to retrieve rewards for
/// @return The rewards across all snapshots for `account`
function getLifetimeRewards(address account) external view returns (uint256);

/// @notice Check if rewards can be accrued.
/// @return Boolean indicating if rewards can be accrued
function canAccrue() external view returns (bool);
Expand Down
5 changes: 5 additions & 0 deletions src/staking/SnapshotStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ contract SnapshotStakingPool is ISnapshotStakingPool, Ownable, ERC20Snapshot, Re
return rewardSnapshots;
}

/// @inheritdoc ISnapshotStakingPool
function getLifetimeRewards(address account) public view returns (uint256) {
return rewardOfInRange(account, 1, _getCurrentSnapshotId());
}

/// @inheritdoc ISnapshotStakingPool
function canAccrue() public view returns (bool) {
return block.timestamp >= lastSnapshotTime + snapshotDelay;
Expand Down
23 changes: 23 additions & 0 deletions test/staking/SnapshotStakingPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,29 @@ contract SnapshotStakingPoolTest is Test {
assertEq(snapshotStakingPool.getRewardSnapshots()[1], 2 ether);
}

function testGetLifetimeRewards() public {
vm.expectRevert(SnapshotStakingPool.NonExistentSnapshotId.selector);
snapshotStakingPool.getLifetimeRewards(bob.addr);

_stake(bob.addr, 1 ether);
_stake(alice.addr, 1 ether);
_snapshot(2 ether);

assertEq(snapshotStakingPool.getLifetimeRewards(bob.addr), 1 ether);
assertEq(snapshotStakingPool.getLifetimeRewards(alice.addr), 1 ether);

_snapshot(2 ether);

assertEq(snapshotStakingPool.getLifetimeRewards(bob.addr), 2 ether);
assertEq(snapshotStakingPool.getLifetimeRewards(alice.addr), 2 ether);

_unstake(alice.addr, 1 ether);
_snapshot(1 ether);

assertEq(snapshotStakingPool.getLifetimeRewards(bob.addr), 3 ether);
assertEq(snapshotStakingPool.getLifetimeRewards(alice.addr), 2 ether);
}

function testCanAccrue() public {
assertEq(snapshotStakingPool.canAccrue(), false);

Expand Down

0 comments on commit 9d80f09

Please sign in to comment.