• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NexusMutual / smart-contracts / #1116

19 Feb 2025 05:09PM UTC coverage: 86.749%. Remained the same
#1116

Pull #1319

rackstar
docs: add TokenController contract docs
Pull Request #1319: docs: add TokenController contract docs

1050 of 1322 branches covered (79.43%)

Branch coverage included in aggregate %.

3081 of 3440 relevant lines covered (89.56%)

170.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/contracts/modules/staking/StakingExtrasLib.sol
1
// SPDX-License-Identifier: GPL-3.0-only
2

3
pragma solidity ^0.8.18;
4

5
import "../../interfaces/IStakingPool.sol";
6
import "../../libraries/Math.sol";
7
import "../../libraries/UncheckedMath.sol";
8
import "../../libraries/SafeUintCast.sol";
9

10
library StakingExtrasLib {
11
  using SafeUintCast for uint;
12
  using UncheckedMath for uint;
13

14
  uint public constant TRANCHE_DURATION = 91 days;
15
  uint public constant MAX_ACTIVE_TRANCHES = 8;
16
  uint public constant POOL_FEE_DENOMINATOR = 100;
17
  uint public constant ONE_NXM = 1 ether;
18

19
  function updateRewardsShares(
20
    // storage refs
21
    mapping(uint => mapping(uint => IStakingPool.Deposit)) storage deposits,
22
    mapping(uint => IStakingPool.Tranche) storage tranches,
23
    // state
24
    uint accNxmPerRewardsShare,
25
    uint rewardsSharesSupply,
26
    uint poolFee,
27
    // input
28
    uint trancheId,
29
    uint[] calldata tokenIds
30
  ) external returns (uint newRewardsSharesSupply) {
31

32
    IStakingPool.Deposit memory feeDeposit = deposits[0][trancheId];
×
33
    IStakingPool.Tranche memory tranche = tranches[trancheId];
×
34

35
    {
×
36
      // update manager's pending rewards
37
      uint newRewardPerRewardsShare = accNxmPerRewardsShare.uncheckedSub(feeDeposit.lastAccNxmPerRewardShare);
×
38
      feeDeposit.pendingRewards += (newRewardPerRewardsShare * feeDeposit.rewardsShares / ONE_NXM).toUint96();
×
39
      feeDeposit.lastAccNxmPerRewardShare = accNxmPerRewardsShare.toUint96();
×
40
    }
41

42
    uint trancheShares;
×
43

44
    for (uint i = 0; i < tokenIds.length; i++) {
×
45
      require(tokenIds[i] != 0, "INVALID_TOKEN_ID");
×
46

47
      // sload and sum up
48
      IStakingPool.Deposit memory deposit = deposits[tokenIds[i]][trancheId];
×
49
      trancheShares += deposit.stakeShares;
×
50

51
      // update
52
      uint newRewardPerRewardsShare = accNxmPerRewardsShare.uncheckedSub(deposit.lastAccNxmPerRewardShare);
×
53
      deposit.pendingRewards += (newRewardPerRewardsShare * deposit.rewardsShares / ONE_NXM).toUint96();
×
54
      deposit.lastAccNxmPerRewardShare = accNxmPerRewardsShare.toUint96();
×
55

56
      // reset rewards shares
57
      deposit.rewardsShares = deposit.stakeShares;
×
58

59
      // sstore
60
      deposits[tokenIds[i]][trancheId] = deposit;
×
61
    }
62

63
    // make sure all deposits (token ids) for the current tranche were included in the input
64
    require(trancheShares == tranche.stakeShares, "INVALID_TOTAL_SHARES");
×
65

66
    // update manager's rewards shares
67
    feeDeposit.rewardsShares = (trancheShares * poolFee / (POOL_FEE_DENOMINATOR - poolFee)).toUint128();
×
68

69
    {
×
70
      // update tranche rewards shares and supply
71
      uint previousRewardsShares = tranche.rewardsShares;
×
72
      uint updatedRewardsShares = trancheShares + feeDeposit.rewardsShares;
×
73

74
      tranche.rewardsShares = updatedRewardsShares.toUint128();
×
75
      rewardsSharesSupply = rewardsSharesSupply - previousRewardsShares + updatedRewardsShares;
×
76
    }
77

78
    // sstore
79
    deposits[0][trancheId] = feeDeposit;
×
80
    tranches[trancheId] = tranche;
×
81

82
    return rewardsSharesSupply;
×
83
  }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc