Skip to content

Commit

Permalink
feat(NexusViewer): add assessment stake lockup expiry timestamp in st…
Browse files Browse the repository at this point in the history
…aked NXM return
  • Loading branch information
mixplore committed Oct 21, 2024
1 parent edd1d89 commit 0a242b9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
7 changes: 6 additions & 1 deletion contracts/interfaces/IAssessmentViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ interface IAssessmentViewer {
uint withdrawableUntilIndex;
}

struct AssessmentStakeLockedState {
bool isStakeLocked;
uint stakeLockupExpiry;
}

function getRewards(address user) external view returns (AssessmentRewards memory);

function isStakeLocked(address member) external view returns (bool stakeLocked);
function getStakeLocked(address member) external view returns (AssessmentStakeLockedState memory);
}
1 change: 1 addition & 0 deletions contracts/interfaces/INexusViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface INexusViewer {
struct StakedNXM {
uint stakingPoolTotalActiveStake; // Total amount of active stake in staking pools in NXM
uint assessmentStake; // Locked assessment stake in NXM
uint assessmentStakeLockupExpiry; // Locked stake expiry timestamp
uint assessmentRewards; // Locked assessment rewards in NXM
}

Expand Down
10 changes: 5 additions & 5 deletions contracts/mocks/modules/NexusViewer/NVMockAssessmentViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {INXMToken} from "../../../interfaces/INXMToken.sol";

contract NVMockAssessmentViewer is IAssessmentViewer {

bool stakeLocked;
AssessmentStakeLockedState stakeLockedState;
AssessmentRewards assessmentRewards;

/* ========== SETTERS ========== */

function setStakeLocked(bool _stakeLocked) external {
stakeLocked = _stakeLocked;
function setStakeLocked(AssessmentStakeLockedState memory _stakeLockedState) external {
stakeLockedState = _stakeLockedState;
}

function setRewards(
Expand All @@ -32,8 +32,8 @@ contract NVMockAssessmentViewer is IAssessmentViewer {

/* ========== VIEWS ========== */

function isStakeLocked(address) external view returns (bool) {
return stakeLocked;
function getStakeLocked(address) external view returns (AssessmentStakeLockedState memory) {
return stakeLockedState;
}

function getRewards(address) external view returns (AssessmentRewards memory) {
Expand Down
19 changes: 14 additions & 5 deletions contracts/modules/assessment/AssessmentViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,29 @@ contract AssessmentViewer is IAssessmentViewer {
});
}

/// @notice Check if the stake of a member is locked
/// @notice Check if the stake of a member is locked and when it will be unlocked
/// @param member The address of the member
/// @return stakeLocked Boolean indicating if the stake is locked
function isStakeLocked(address member) external view returns (bool stakeLocked) {
/// @return AssessmentStakeLockedState structure containing locked stake details
function getStakeLocked(address member) external view returns (AssessmentStakeLockedState memory) {

IAssessment _assessment = assessment();

uint voteCount = _assessment.getVoteCountOfAssessor(member);
if (voteCount == 0) return false;
if (voteCount == 0) return AssessmentStakeLockedState({
isStakeLocked: false,
stakeLockupExpiry: 0
});

(,, uint32 timestamp,) = _assessment.votesOf(member, voteCount - 1);
(, uint8 stakeLockupPeriodInDays,,) = _assessment.config();

uint stakeLockupExpiry = timestamp + stakeLockupPeriodInDays * 1 days;
stakeLocked = stakeLockupExpiry > block.timestamp;
bool isStakeLocked = stakeLockupExpiry > block.timestamp;

return AssessmentStakeLockedState({
isStakeLocked: isStakeLocked,
stakeLockupExpiry: stakeLockupExpiry
});

}
}
13 changes: 7 additions & 6 deletions contracts/modules/viewer/NexusViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract NexusViewer is INexusViewer, Multicall {

// Assessment
IAssessmentViewer.AssessmentRewards memory assessmentRewards = assessmentViewer.getRewards(member);
(uint assessmentStake, bool isStakeLocked) = _getAssessmentStake(member);
(uint assessmentStake, IAssessmentViewer.AssessmentStakeLockedState memory stakeLockedState) = _getAssessmentStake(member);

// Staking Pool
IStakingViewer.AggregatedTokens memory aggregatedTokens = stakingViewer.getAggregatedTokens(tokenIds);
Expand All @@ -53,7 +53,7 @@ contract NexusViewer is INexusViewer, Multicall {
return ClaimableNXM({
governanceRewards: governanceRewards,
assessmentRewards: assessmentRewards.withdrawableAmountInNXM,
assessmentStake: isStakeLocked ? 0 : assessmentStake,
assessmentStake: stakeLockedState.isStakeLocked ? 0 : assessmentStake,
stakingPoolTotalRewards: aggregatedTokens.totalRewards,
stakingPoolTotalExpiredStake: aggregatedTokens.totalExpiredStake,
managerTotalRewards: managerTotalRewards,
Expand All @@ -74,18 +74,19 @@ contract NexusViewer is INexusViewer, Multicall {
IStakingViewer.AggregatedTokens memory aggregatedTokens = stakingViewer.getAggregatedTokens(tokenIds);

IAssessmentViewer.AssessmentRewards memory assessmentRewards = assessmentViewer.getRewards(member);
(uint assessmentStake, bool isStakeLocked) = _getAssessmentStake(member);
(uint assessmentStake, IAssessmentViewer.AssessmentStakeLockedState memory stakeLockedState) = _getAssessmentStake(member);

return StakedNXM({
stakingPoolTotalActiveStake: aggregatedTokens.totalActiveStake,
assessmentStake: isStakeLocked ? assessmentStake : 0,
assessmentStake: stakeLockedState.isStakeLocked ? assessmentStake : 0,
assessmentStakeLockupExpiry: stakeLockedState.stakeLockupExpiry,
assessmentRewards: assessmentRewards.totalPendingAmountInNXM - assessmentRewards.withdrawableAmountInNXM
});
}

function _getAssessmentStake(address member) internal view returns (uint assessmentStake, bool isStakeLocked) {
function _getAssessmentStake(address member) internal view returns (uint assessmentStake, IAssessmentViewer.AssessmentStakeLockedState memory stakeLockedState) {
(assessmentStake, , ) = _assessment().stakeOf(member);
isStakeLocked = assessmentViewer.isStakeLocked(member);
stakeLockedState = assessmentViewer.getStakeLocked(member);
}

/* ========== DEPENDENCIES ========== */
Expand Down

0 comments on commit 0a242b9

Please sign in to comment.