Skip to content
Verified contractExactGPL-3.0-only

Governor

Address0xcafea466bf6defe480cdd54056c020c63b7da830
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.28

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 200 runs
EVM version
prague
License
GPL-3.0-only
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
23,683,032
Creation transaction
0x1babdf433b…1daa414a97

contracts/modules/governance/Governor.sol

// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.28;

import "../../abstract/Multicall.sol";
import "../../abstract/RegistryAware.sol";
import "../../interfaces/IGovernor.sol";
import "../../interfaces/IRegistry.sol";
import "../../interfaces/ITokenController.sol";
import "../../libraries/SafeUintCast.sol";

contract Governor is IGovernor, RegistryAware, Multicall {
  using SafeUintCast for uint;

  /* ========== storage ========== */

  uint public proposalCount;

  mapping(uint proposalId => Proposal) internal proposals;

  mapping(uint proposalId => string) internal descriptions;

  mapping(uint proposalId => Transaction[]) internal transactions;

  mapping(uint proposalId => Tally) internal tallies;

  mapping(uint proposalId => mapping(uint memberId => Vote)) internal votes;

  /* ========== immutables and constants ========== */

  ITokenController public immutable tokenController;

  uint public constant TIMELOCK_PERIOD = 1 days;
  uint public constant VOTING_PERIOD = 3 days;
  uint public constant ADVISORY_BOARD_THRESHOLD = 3;
  uint public constant MEMBER_VOTE_QUORUM_PERCENTAGE = 15; // 15% of token supply
  uint public constant PROPOSAL_THRESHOLD = 100 ether; // minimum 100 tokens to open an AB swap proposal
  uint public constant VOTE_WEIGHT_CAP_PERCENTAGE = 5; // 5%

  /* ========== logic ========== */

  constructor(address _registry) RegistryAware(_registry) {
    tokenController = ITokenController(fetch(C_TOKEN_CONTROLLER));
  }

  function getVoteWeight(address voter) public view returns (uint) {
    return registry.isMember(voter) ? _getVoteWeight(voter) : 0;
  }

  function _getVoteWeight(address voter) internal view returns (uint) {
    uint totalSupply = tokenController.totalSupply();
    uint weight = tokenController.totalBalanceOf(voter) + 1 ether;
    uint maxWeight = totalSupply * VOTE_WEIGHT_CAP_PERCENTAGE / 100;
    return weight > maxWeight ? maxWeight : weight;
  }

  function _lockTokenTransfers(address voter, uint deadline) internal {
    uint duration = deadline - block.timestamp;
    tokenController.lockForMemberVote(voter, duration);
  }

  function propose(
    Transaction[] calldata txs,
    string calldata description
  ) external returns (uint proposalId) {
    require(registry.isAdvisoryBoardMember(msg.sender), OnlyAdvisoryBoardMember());
    return _propose(ProposalKind.AdvisoryBoard, txs, description);
  }

  function proposeAdvisoryBoardSwap(
    AdvisoryBoardSwap[] memory swaps,
    string calldata description
  ) external returns (uint proposalId) {

    require(registry.isMember(msg.sender), NotMember());

    // prevent spam
    uint weight = _getVoteWeight(msg.sender);
    require(weight > PROPOSAL_THRESHOLD, ProposalThresholdNotMet());

    Transaction[] memory txs = new Transaction[](swaps.length);

    for (uint i = 0; i < swaps.length; i++) {

      require(swaps[i].from != swaps[i].to, InvalidAdvisoryBoardSwap());
      require(swaps[i].from != 0 && swaps[i].to != 0, InvalidAdvisoryBoardSwap());
      require(registry.isAdvisoryBoardMemberById(swaps[i].from), InvalidAdvisoryBoardSwap());
      require(registry.getMemberAddress(swaps[i].to) != address(0), NotMember());

      txs[i] = Transaction({
        target: address(registry),
        value: 0,
        data: abi.encodeWithSelector(registry.swapAdvisoryBoardMember.selector, swaps[i].from, swaps[i].to)
      });
    }

    return _propose(ProposalKind.Member, txs, description);
  }

  function _propose(
    ProposalKind kind,
    Transaction[] memory txs,
    string memory description
  ) internal returns (uint proposalId) {

    Proposal memory proposal = Proposal({
      kind: kind,
      proposedAt: block.timestamp.toUint32(),
      voteBefore: (block.timestamp + VOTING_PERIOD).toUint32(),
      executeAfter: (block.timestamp + VOTING_PERIOD + TIMELOCK_PERIOD).toUint32(),
      status: ProposalStatus.Proposed
    });

    proposalId = ++proposalCount;
    proposals[proposalId] = proposal;
    descriptions[proposalId] = description;

    for (uint i = 0; i < txs.length; i++) {
      transactions[proposalId].push(txs[i]);
    }

    emit ProposalCreated(proposalId, kind, description);

    return proposalId;
  }

  function cancel(uint proposalId) external {

    require(registry.isAdvisoryBoardMember(msg.sender), OnlyAdvisoryBoardMember());

    Proposal memory proposal = proposals[proposalId];
    require(proposal.proposedAt > 0, ProposalNotFound());
    require(proposal.kind == ProposalKind.AdvisoryBoard, CannotCancelMemberProposal());
    require(proposal.status != ProposalStatus.Executed, ProposalAlreadyExecuted());
    require(proposal.status != ProposalStatus.Canceled, ProposalIsCanceled());

    proposal.status = ProposalStatus.Canceled;
    proposals[proposalId] = proposal;

    emit ProposalCanceled(proposalId);
  }

  function vote(uint proposalId, Choice choice) external {

    Proposal memory proposal = proposals[proposalId];
    require(proposal.proposedAt > 0, ProposalNotFound());
    require(block.timestamp < proposal.voteBefore, VotePeriodHasEnded());
    require(proposal.status != ProposalStatus.Executed, ProposalAlreadyExecuted());
    require(proposal.status != ProposalStatus.Canceled, ProposalIsCanceled());

    uint memberId = registry.getMemberId(msg.sender);
    require(memberId > 0, NotMember());

    bool isAbProposal = proposal.kind == ProposalKind.AdvisoryBoard;
    uint voterId = isAbProposal
      ? registry.getAdvisoryBoardSeat(msg.sender)
      : memberId;
    require(votes[proposalId][voterId].weight == 0, AlreadyVoted());

    uint96 weight = (isAbProposal ? 1 : _getVoteWeight(msg.sender)).toUint96();
    votes[proposalId][voterId] = Vote({ choice: choice, weight: weight });

    if (choice == Choice.For) {
      tallies[proposalId].forVotes += weight;
    }

    if (choice == Choice.Against) {
      tallies[proposalId].againstVotes += weight;
    }

    if (choice == Choice.Abstain) {
      tallies[proposalId].abstainVotes += weight;
    }

    if (isAbProposal && tallies[proposalId].forVotes >= ADVISORY_BOARD_THRESHOLD) {
      // start the timelock if the AB proposal has met the threshold
      proposal.executeAfter = (block.timestamp + TIMELOCK_PERIOD).toUint32();
      proposals[proposalId].executeAfter = proposal.executeAfter;
      proposals[proposalId].voteBefore = block.timestamp.toUint32();
    }

    if(!isAbProposal) {
      _lockTokenTransfers(msg.sender, proposal.executeAfter);
    }

    emit VoteCast(proposalId, proposal.kind, voterId, choice, weight);
  }

  function _performCall(address target, uint value, bytes memory data, uint txIndex) internal {

    // if data is not empty - the target is assumed to be a contract
    require(data.length == 0 || target.code.length != 0, TargetIsNotAContract());

    (bool ok, bytes memory returndata) = target.call{value: value}(data);

    if (ok) {
      return;
    }

    uint size = returndata.length;

    if (size == 0) {
      revert RevertedWithoutReason(txIndex);
    }

    // bubble up the revert reason
    assembly {
      revert(add(returndata, 0x20), size)
    }
  }

  function execute(uint proposalId) external payable {

    Proposal memory proposal = proposals[proposalId];
    require(proposal.proposedAt > 0, ProposalNotFound());
    require(proposal.status != ProposalStatus.Executed, ProposalAlreadyExecuted());
    require(proposal.status != ProposalStatus.Canceled, ProposalIsCanceled());

    bool isAbProposal = proposal.kind == ProposalKind.AdvisoryBoard;
    require(isAbProposal || registry.isMember(msg.sender), NotMember());
    require(!isAbProposal || registry.isAdvisoryBoardMember(msg.sender), OnlyAdvisoryBoardMember());
    require(block.timestamp > proposal.executeAfter, TimelockHasNotEnded());

    Tally memory tally = tallies[proposalId];
    require(tally.forVotes > tally.againstVotes, VoteTalliedAgainst());

    if (isAbProposal) {
      require(tally.forVotes >= ADVISORY_BOARD_THRESHOLD, VoteThresholdNotMet());
    } else {
      uint quorum = tokenController.totalSupply() * MEMBER_VOTE_QUORUM_PERCENTAGE / 100;
      uint totalVotes = tally.forVotes + tally.againstVotes + tally.abstainVotes;
      require(totalVotes >= quorum, VoteQuorumNotMet());
    }

    Transaction[] memory txs = transactions[proposalId];

    for (uint i = 0; i < txs.length; i++) {
      _performCall(txs[i].target, txs[i].value, txs[i].data, i);
    }

    proposal.status = ProposalStatus.Executed;
    proposals[proposalId] = proposal;

    emit ProposalExecuted(proposalId);
  }

  function getProposal(uint proposalId) external view returns (Proposal memory) {
    return proposals[proposalId];
  }

  function getProposalDescription(uint proposalId) external view returns (string memory) {
    return descriptions[proposalId];
  }

  function getProposalTransactions(uint proposalId) external view returns (Transaction[] memory) {
    return transactions[proposalId];
  }

  function getProposalTally(uint proposalId) external view returns (Tally memory) {
    return tallies[proposalId];
  }

  function getProposalWithDetails(uint _proposalId) external view returns (
    uint proposalId,
    Proposal memory,
    string memory,
    Transaction[] memory,
    Tally memory
  ) {
    return (
      _proposalId,
      proposals[_proposalId],
      descriptions[_proposalId],
      transactions[_proposalId],
      tallies[_proposalId]
    );
  }

  function getVote(uint proposalId, uint memberId) external view returns (Vote memory) {
    return votes[proposalId][memberId];
  }

}

contracts/abstract/Multicall.sol

// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.18;

abstract contract Multicall {

  error RevertedWithoutReason(uint index);

  // WARNING: Do not set this function as payable
  function multicall(bytes[] calldata data) external returns (bytes[] memory results) {

    uint callCount = data.length;
    results = new bytes[](callCount);

    for (uint i = 0; i < callCount; i++) {
      (bool ok, bytes memory result) = address(this).delegatecall(data[i]);

      if (!ok) {

        uint length = result.length;

        // 0 length returned from empty revert() / require(false)
        if (length == 0) {
          revert RevertedWithoutReason(i);
        }

        assembly {
          revert(add(result, 0x20), length)
        }
      }

      results[i] = result;
    }
  }
}

contracts/abstract/RegistryAware.sol

// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.28;

import "../interfaces/IRegistry.sol";

// contract indexes
uint constant C_REGISTRY             = 1 << 0;   // 1
uint constant C_GOVERNOR             = 1 << 1;   // 2
uint constant C_TOKEN                = 1 << 2;   // 4
uint constant C_TOKEN_CONTROLLER     = 1 << 3;   // 8
uint constant C_POOL                 = 1 << 4;   // 16
uint constant C_COVER                = 1 << 5;   // 32
uint constant C_COVER_PRODUCTS       = 1 << 6;   // 64
uint constant C_STAKING_PRODUCTS     = 1 << 7;   // 128
uint constant C_RAMM                 = 1 << 8;   // 256
uint constant C_SAFE_TRACKER         = 1 << 9;   // 512
uint constant C_LIMIT_ORDERS         = 1 << 10;  // 1024
uint constant C_STAKING_NFT          = 1 << 11;  // 2048
uint constant C_COVER_NFT            = 1 << 12;  // 4096
uint constant C_SWAP_OPERATOR        = 1 << 13;  // 8192
uint constant C_ASSESSMENTS          = 1 << 14;  // 16384
uint constant C_CLAIMS               = 1 << 15;  // 32768
uint constant C_STAKING_POOL_FACTORY = 1 << 16;  // 65536

// pause types constants
uint constant PAUSE_GLOBAL        = 1 << 0;   // 1
uint constant PAUSE_RAMM          = 1 << 1;   // 2
uint constant PAUSE_SWAPS         = 1 << 2;   // 4
uint constant PAUSE_MEMBERSHIP    = 1 << 3;   // 8
uint constant PAUSE_ASSESSMENTS   = 1 << 4;   // 16
uint constant PAUSE_CLAIMS        = 1 << 5;   // 32
uint constant PAUSE_COVER         = 1 << 6;   // 64

contract RegistryAware {

  IRegistry public immutable registry;

  error Paused(uint currentState, uint checks);
  error Unauthorized(address caller, uint callerIndex, uint authorizedBitmap);
  error OnlyMember();
  error OnlyAdvisoryBoard();

  modifier whenNotPaused(uint mask) {
    uint config = registry.getPauseConfig();
    uint maskWithGlobal = mask | PAUSE_GLOBAL;
    require(config & maskWithGlobal == 0, Paused(config, mask));
    _;
  }

  modifier onlyContracts(uint authorizedBitmap) {
    uint callerIndex = msg.sender == address(registry)
      ? C_REGISTRY
      : registry.getContractIndexByAddress(msg.sender);
    bool isAuthorized = callerIndex & authorizedBitmap != 0;
    require(isAuthorized, Unauthorized(msg.sender, callerIndex, authorizedBitmap));
    _;
  }

  modifier onlyAdvisoryBoard() {
    require(registry.isAdvisoryBoardMember(msg.sender), OnlyAdvisoryBoard());
    _;
  }

  modifier onlyMember() {
    require(registry.isMember(msg.sender), OnlyMember());
    _;
  }

  function fetch(uint index) internal view returns (address) {
    return registry.getContractAddressByIndex(index);
  }

  constructor(address _registry) {
    registry = IRegistry(_registry);
  }

}

contracts/interfaces/IGovernor.sol

// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface IGovernor {

  enum ProposalKind {
    AdvisoryBoard,
    Member
  }

  enum Choice {
    Against,
    For,
    Abstain
  }

  enum ProposalStatus {
    Proposed,
    Executed,
    Canceled
  }

  struct Proposal { // 112 bits
    ProposalKind kind;
    ProposalStatus status;
    uint32 proposedAt;
    uint32 voteBefore;
    uint32 executeAfter;
  }

  struct Transaction {
    address target;
    uint96 value;
    bytes data;
  }

  struct Vote {
    Choice choice;
    uint96 weight;
  }

  struct Tally {
    uint96 againstVotes;
    uint96 forVotes;
    uint96 abstainVotes;
  }

  struct AdvisoryBoardSwap {
    uint from; // memberId
    uint to; // memberId
  }

  function propose(Transaction[] calldata transactions, string calldata description) external returns (uint proposalId);
  function execute(uint proposalId) external payable;

  function getVoteWeight(address voter) external view returns (uint);

  function getProposal(uint proposalId) external view returns (Proposal memory);
  function getProposalDescription(uint proposalId) external view returns (string memory);
  function getProposalTransactions(uint proposalId) external view returns (Transaction[] memory);
  function getProposalTally(uint proposalId) external view returns (Tally memory);
  function getProposalWithDetails(uint _proposalId) external view returns (
    uint proposalId,
    Proposal memory,
    string memory,
    Transaction[] memory,
    Tally memory
  );
  function getVote(uint proposalId, uint memberId) external view returns (Vote memory);

  event ProposalExecuted(uint proposalId);
  event VoteCast(uint indexed proposalId, ProposalKind indexed kind, uint indexed voterId, Choice choice, uint weight);
  event ProposalCanceled(uint proposalId);
  event ProposalCreated(uint proposalId, ProposalKind kind, string description);

  error InvalidAdvisoryBoardSwap();
  error AlreadyAdvisoryBoardMember();
  error OnlyAdvisoryBoardMember();
  error OnlyGovernor();
  error NotMember();
  error NotAuthorizedToVote();

  error ProposalNotFound();
  error ProposalAlreadyExecuted();
  error ProposalIsCanceled();

  // voting
  error VotePeriodHasEnded();
  error VoteTalliedAgainst();
  error VoteThresholdNotMet();
  error VoteQuorumNotMet();
  error ProposalThresholdNotMet();
  error AlreadyVoted();

  // cancellation
  error CannotCancelMemberProposal();

  // execution
  error ExecutionPeriodHasEnded();
  error TimelockHasNotEnded();
  error TargetIsNotAContract();

}

contracts/interfaces/INXMToken.sol

// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface INXMToken {

  function burn(uint256 amount) external returns (bool);

  function burnFrom(address from, uint256 value) external returns (bool);

  function operatorTransfer(address from, uint256 value) external returns (bool);

  function mint(address account, uint256 amount) external;

  function isLockedForMV(address member) external view returns (uint);

  function whiteListed(address member) external view returns (bool);

  function addToWhiteList(address _member) external returns (bool);

  function removeFromWhiteList(address _member) external returns (bool);

  function changeOperator(address _newOperator) external returns (bool);

  function lockForMemberVote(address _of, uint _days) external;

  /**
 * @dev Returns the amount of tokens in existence.
 */
  function totalSupply() external view returns (uint256);

  /**
   * @dev Returns the amount of tokens owned by `account`.
   */
  function balanceOf(address account) external view returns (uint256);

  /**
   * @dev Moves `amount` tokens from the caller's account to `recipient`.
   *
   * Returns a boolean value indicating whether the operation succeeded.
   *
   * Emits a {Transfer} event.
   */
  function transfer(address recipient, uint256 amount) external returns (bool);

  /**
   * @dev Returns the remaining number of tokens that `spender` will be
   * allowed to spend on behalf of `owner` through {transferFrom}. This is
   * zero by default.
   *
   * This value changes when {approve} or {transferFrom} are called.
   */
  function allowance(address owner, address spender) external view returns (uint256);

  /**
   * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
   *
   * Returns a boolean value indicating whether the operation succeeded.
   *
   * IMPORTANT: Beware that changing an allowance with this method brings the risk
   * that someone may use both the old and the new allowance by unfortunate
   * transaction ordering. One possible solution to mitigate this race
   * condition is to first reduce the spender's allowance to 0 and set the
   * desired value afterwards:
   * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
   *
   * Emits an {Approval} event.
   */
  function approve(address spender, uint256 amount) external returns (bool);

  /**
   * @dev Moves `amount` tokens from `sender` to `recipient` using the
   * allowance mechanism. `amount` is then deducted from the caller's
   * allowance.
   *
   * Returns a boolean value indicating whether the operation succeeded.
   *
   * Emits a {Transfer} event.
   */
  function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

  /**
   * @dev Emitted when `value` tokens are moved from one account (`from`) to
   * another (`to`).
   *
   * Note that `value` may be zero.
   */
  event Transfer(address indexed from, address indexed to, uint256 value);

  /**
   * @dev Emitted when the allowance of a `spender` for an `owner` is set by
   * a call to {approve}. `value` is the new allowance.
   */
  event Approval(address indexed owner, address indexed spender, uint256 value);
}

contracts/interfaces/IRegistry.sol

// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.8.0;

interface IRegistry {

  struct Contract {
    address addr;
    bool isProxy;
  }

  struct SystemPause {
    uint48 config;
    uint48 proposedConfig;
    address proposer;
  }

  struct MembersMeta {
    uint48 memberCount;
    uint48 lastMemberId;
    address kycAuthAddress;
  }

  /* == EMERGENCY PAUSE == */
  function setEmergencyAdmin(address _emergencyAdmin, bool enabled) external;
  function proposePauseConfig(uint config) external;
  function confirmPauseConfig(uint config) external;
  function getSystemPause() external view returns (SystemPause memory);
  function getPauseConfig() external view returns (uint config);
  function isPaused(uint mask) external view returns (bool);
  function isEmergencyAdmin(address member) external view returns (bool);

  /* == MEMBERSHIP MANAGEMENT == */
  function isMember(address member) external view returns (bool);
  function getMemberId(address member) external view returns (uint);
  function getMemberAddress(uint memberId) external view returns (address);
  function getMemberCount() external view returns (uint);
  function getLastMemberId() external view returns (uint);
  function join(address member, bytes memory signature) external payable;
  function switchTo(address to) external;
  function switchFor(address from, address to) external;
  function leave() external;
  function setKycAuthAddress(address kycAuthAddress) external;
  function getKycAuthAddress() external view returns (address);

  /* == ADVISORY BOARD MANAGEMENT == */
  function isAdvisoryBoardMember(address member) external view returns (bool);
  function isAdvisoryBoardMemberById(uint memberId) external view returns (bool);
  function getAdvisoryBoardSeat(address member) external view returns (uint);
  function getMemberAddressBySeat(uint seat) external view returns (address);
  function swapAdvisoryBoardMember(uint from, uint to) external;

  /* == CONTRACT MANAGEMENT == */
  function isValidContractIndex(uint index) external pure returns (bool);
  function isProxyContract(uint index) external view returns (bool);
  function getContractAddressByIndex(uint index) external view returns (address payable);
  function getContractIndexByAddress(address contractAddress) external view returns (uint);
  function getContracts(uint[] memory indexes) external view returns (Contract[] memory);
  function deployContract(uint index, bytes32 salt, address implementation) external;
  function addContract(uint index, address contractAddress, bool isProxy) external;
  function upgradeContract(uint index, address implementation) external;
  function removeContract(uint index) external;

  /* == MIGRATIONS == */
  function migrateMembers(address[] calldata membersToMigrate) external;
  function migrateAdvisoryBoardMembers(address[] calldata abMembers) external;

  // joined: MembershipChanged(memberId, address(0), current)
  // swapped: MembershipChanged(memberId, previous, current)
  // left: MembershipChanged(memberId, current, address(0))
  event MembershipChanged(uint indexed memberId, address indexed previous, address indexed current);
  event AdvisoryBoardMemberSwapped(uint indexed seat, uint indexed from, uint indexed to);

  event ContractDeployed(uint indexed index, address indexed proxy, address implementation);
  event ContractUpgraded(uint indexed index, address indexed proxy, address implementation);
  event ContractAdded(uint indexed index, address indexed contractAddress, bool isProxy);
  event ContractRemoved(uint indexed index, address indexed contractAddress, bool isProxy);

  event EmergencyAdminSet(address indexed emergencyAdmin, bool enabled);
  event PauseConfigProposed(uint config, address indexed proposer);
  event PauseConfigConfirmed(uint config, address indexed confirmer);

  error ContractAlreadyExists();
  error InvalidContractIndex();
  error InvalidContractAddress();
  error ContractDoesNotExist();
  error ContractIsNotProxy();

  error OnlyEmergencyAdmin();
  error ProposerCannotConfirmPause();
  error PauseConfigMismatch();
  error NoConfigProposed();
  error Paused(uint currentState, uint checks);

  error NotMember();
  error AlreadyMember();
  error AddressAlreadyUsedForJoining();
  error InvalidJoinFee();
  error InvalidSignature();
  error FeeTransferFailed();

  error NotAdvisoryBoardMember();
  error AlreadyAdvisoryBoardMember();
  error AdvisoryBoardMemberCannotLeave();
  error InvalidSeat();

  error OnlyGovernor();
  error NotProxyOwner();
  error NotMemberRoles();

}

contracts/interfaces/ITokenController.sol

// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "./INXMToken.sol";

interface ITokenController {

  struct StakingPoolNXMBalances {
    uint128 rewards;
    uint128 deposits;
  }

  struct StakingPoolOwnershipOffer {
    address proposedManager;
    uint96 deadline;
  }

  struct WithdrawAssessment {
    bool stake;
    bool rewards;
  }

  /// @notice The stake deposit / rewards in a staking pool that will be withdrawn.
  /// @dev    Call StakingViewer.getToken to get tokenId / trancheId information
  /// @param tokenId The ID of the token stake deposit / rewards that will be withrawn.
  /// @param trancheIds An array of tranche IDs representing the tranches where the stake was deposited.
  struct StakingPoolDeposit {
    uint tokenId;
    uint[] trancheIds;
  }

  /// @notice Represents the rewards distributed to a staking pool manager.
  /// @dev    Call StakingViewer.getManagerTokenRewardsByAddr to get poolId / trancheId information
  /// @param poolId The ID of the pool managed by the manager.
  /// @param trancheIds An array of tranche IDs representing the tranches where the manager rewards were distributed.
  struct StakingPoolManagerReward {
    uint poolId;
    uint[] trancheIds;
  }

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

  function token() external view returns (INXMToken);

  function totalSupply() external view returns (uint);

  function totalBalanceOf(address _of) external view returns (uint amount);

  function totalBalanceOfWithoutDelegations(address _of) external view returns (uint amount);

  function getTokenPrice() external view returns (uint tokenPrice);

  function getStakingPoolManager(uint poolId) external view returns (address manager);

  function getManagerStakingPools(address manager) external view returns (uint[] memory poolIds);

  function isStakingPoolManager(address member) external view returns (bool);

  function getStakingPoolOwnershipOffer(uint poolId) external view returns (address proposedManager, uint deadline);

  function stakingPoolNXMBalances(uint poolId) external view returns (uint128 rewards, uint128 deposits);

  /* ========== MUTATIVE FUNCTIONS ========== */

  function changeOperator(address _newOperator) external;

  function operatorTransfer(address _from, address _to, uint _value) external returns (bool);

  function burnFrom(address _of, uint amount) external returns (bool);

  function addToWhitelist(address _member) external;

  function removeFromWhitelist(address _member) external;

  function switchMembership(address from, address to, bool includeNxmTokens) external;

  function mint(address _member, uint _amount) external;

  function lockForMemberVote(address _of, uint _days) external;

  function assignStakingPoolManager(uint poolId, address manager) external;

  function createStakingPoolOwnershipOffer(uint poolId, address proposedManager, uint deadline) external;

  function acceptStakingPoolOwnershipOffer(uint poolId) external;

  function cancelStakingPoolOwnershipOffer(uint poolId) external;

  function mintStakingPoolNXMRewards(uint amount, uint poolId) external;

  function burnStakingPoolNXMRewards(uint amount, uint poolId) external;

  function depositStakedNXM(address from, uint amount, uint poolId) external;

  function withdrawNXMStakeAndRewards(address to, uint stakeToWithdraw, uint rewardsToWithdraw, uint poolId) external;

  function burnStakedNXM(uint amount, uint poolId) external;
}

contracts/libraries/SafeUintCast.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

/**
 * @dev Wrappers over Solidity's uintXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeUintCast {
  /**
   * @dev Returns the downcasted uint248 from uint256, reverting on
   * overflow (when the input is greater than largest uint248).
   *
   * Counterpart to Solidity's `uint248` operator.
   *
   * Requirements:
   *
   * - input must fit into 248 bits
   */
  function toUint248(uint256 value) internal pure returns (uint248) {
    require(value < 2**248, "SafeCast: value doesn\'t fit in 248 bits");
    return uint248(value);
  }

  /**
   * @dev Returns the downcasted uint240 from uint256, reverting on
   * overflow (when the input is greater than largest uint240).
   *
   * Counterpart to Solidity's `uint240` operator.
   *
   * Requirements:
   *
   * - input must fit into 240 bits
   */
  function toUint240(uint256 value) internal pure returns (uint240) {
    require(value < 2**240, "SafeCast: value doesn\'t fit in 240 bits");
    return uint240(value);
  }

  /**
   * @dev Returns the downcasted uint232 from uint256, reverting on
   * overflow (when the input is greater than largest uint232).
   *
   * Counterpart to Solidity's `uint232` operator.
   *
   * Requirements:
   *
   * - input must fit into 232 bits
   */
  function toUint232(uint256 value) internal pure returns (uint232) {
    require(value < 2**232, "SafeCast: value doesn\'t fit in 232 bits");
    return uint232(value);
  }

  /**
   * @dev Returns the downcasted uint224 from uint256, reverting on
   * overflow (when the input is greater than largest uint224).
   *
   * Counterpart to Solidity's `uint224` operator.
   *
   * Requirements:
   *
   * - input must fit into 224 bits
   */
  function toUint224(uint256 value) internal pure returns (uint224) {
    require(value < 2**224, "SafeCast: value doesn\'t fit in 224 bits");
    return uint224(value);
  }

  /**
   * @dev Returns the downcasted uint216 from uint256, reverting on
   * overflow (when the input is greater than largest uint216).
   *
   * Counterpart to Solidity's `uint216` operator.
   *
   * Requirements:
   *
   * - input must fit into 216 bits
   */
  function toUint216(uint256 value) internal pure returns (uint216) {
    require(value < 2**216, "SafeCast: value doesn\'t fit in 216 bits");
    return uint216(value);
  }

  /**
   * @dev Returns the downcasted uint208 from uint256, reverting on
   * overflow (when the input is greater than largest uint208).
   *
   * Counterpart to Solidity's `uint208` operator.
   *
   * Requirements:
   *
   * - input must fit into 208 bits
   */
  function toUint208(uint256 value) internal pure returns (uint208) {
    require(value < 2**208, "SafeCast: value doesn\'t fit in 208 bits");
    return uint208(value);
  }

  /**
   * @dev Returns the downcasted uint200 from uint256, reverting on
   * overflow (when the input is greater than largest uint200).
   *
   * Counterpart to Solidity's `uint200` operator.
   *
   * Requirements:
   *
   * - input must fit into 200 bits
   */
  function toUint200(uint256 value) internal pure returns (uint200) {
    require(value < 2**200, "SafeCast: value doesn\'t fit in 200 bits");
    return uint200(value);
  }

  /**
   * @dev Returns the downcasted uint192 from uint256, reverting on
   * overflow (when the input is greater than largest uint192).
   *
   * Counterpart to Solidity's `uint192` operator.
   *
   * Requirements:
   *
   * - input must fit into 192 bits
   */
  function toUint192(uint256 value) internal pure returns (uint192) {
    require(value < 2**192, "SafeCast: value doesn\'t fit in 192 bits");
    return uint192(value);
  }

  /**
   * @dev Returns the downcasted uint184 from uint256, reverting on
   * overflow (when the input is greater than largest uint184).
   *
   * Counterpart to Solidity's `uint184` operator.
   *
   * Requirements:
   *
   * - input must fit into 184 bits
   */
  function toUint184(uint256 value) internal pure returns (uint184) {
    require(value < 2**184, "SafeCast: value doesn\'t fit in 184 bits");
    return uint184(value);
  }

  /**
   * @dev Returns the downcasted uint176 from uint256, reverting on
   * overflow (when the input is greater than largest uint176).
   *
   * Counterpart to Solidity's `uint176` operator.
   *
   * Requirements:
   *
   * - input must fit into 176 bits
   */
  function toUint176(uint256 value) internal pure returns (uint176) {
    require(value < 2**176, "SafeCast: value doesn\'t fit in 176 bits");
    return uint176(value);
  }

  /**
   * @dev Returns the downcasted uint168 from uint256, reverting on
   * overflow (when the input is greater than largest uint168).
   *
   * Counterpart to Solidity's `uint168` operator.
   *
   * Requirements:
   *
   * - input must fit into 168 bits
   */
  function toUint168(uint256 value) internal pure returns (uint168) {
    require(value < 2**168, "SafeCast: value doesn\'t fit in 168 bits");
    return uint168(value);
  }

  /**
   * @dev Returns the downcasted uint160 from uint256, reverting on
   * overflow (when the input is greater than largest uint160).
   *
   * Counterpart to Solidity's `uint160` operator.
   *
   * Requirements:
   *
   * - input must fit into 160 bits
   */
  function toUint160(uint256 value) internal pure returns (uint160) {
    require(value < 2**160, "SafeCast: value doesn\'t fit in 160 bits");
    return uint160(value);
  }

  /**
   * @dev Returns the downcasted uint152 from uint256, reverting on
   * overflow (when the input is greater than largest uint152).
   *
   * Counterpart to Solidity's `uint152` operator.
   *
   * Requirements:
   *
   * - input must fit into 152 bits
   */
  function toUint152(uint256 value) internal pure returns (uint152) {
    require(value < 2**152, "SafeCast: value doesn\'t fit in 152 bits");
    return uint152(value);
  }

  /**
   * @dev Returns the downcasted uint144 from uint256, reverting on
   * overflow (when the input is greater than largest uint144).
   *
   * Counterpart to Solidity's `uint144` operator.
   *
   * Requirements:
   *
   * - input must fit into 144 bits
   */
  function toUint144(uint256 value) internal pure returns (uint144) {
    require(value < 2**144, "SafeCast: value doesn\'t fit in 144 bits");
    return uint144(value);
  }

  /**
   * @dev Returns the downcasted uint136 from uint256, reverting on
   * overflow (when the input is greater than largest uint136).
   *
   * Counterpart to Solidity's `uint136` operator.
   *
   * Requirements:
   *
   * - input must fit into 136 bits
   */
  function toUint136(uint256 value) internal pure returns (uint136) {
    require(value < 2**136, "SafeCast: value doesn\'t fit in 136 bits");
    return uint136(value);
  }

  /**
   * @dev Returns the downcasted uint128 from uint256, reverting on
   * overflow (when the input is greater than largest uint128).
   *
   * Counterpart to Solidity's `uint128` operator.
   *
   * Requirements:
   *
   * - input must fit into 128 bits
   */
  function toUint128(uint256 value) internal pure returns (uint128) {
    require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits");
    return uint128(value);
  }

  /**
   * @dev Returns the downcasted uint120 from uint256, reverting on
   * overflow (when the input is greater than largest uint120).
   *
   * Counterpart to Solidity's `uint120` operator.
   *
   * Requirements:
   *
   * - input must fit into 120 bits
   */
  function toUint120(uint256 value) internal pure returns (uint120) {
    require(value < 2**120, "SafeCast: value doesn\'t fit in 120 bits");
    return uint120(value);
  }

  /**
   * @dev Returns the downcasted uint112 from uint256, reverting on
   * overflow (when the input is greater than largest uint112).
   *
   * Counterpart to Solidity's `uint112` operator.
   *
   * Requirements:
   *
   * - input must fit into 112 bits
   */
  function toUint112(uint256 value) internal pure returns (uint112) {
    require(value < 2**112, "SafeCast: value doesn\'t fit in 112 bits");
    return uint112(value);
  }

  /**
   * @dev Returns the downcasted uint104 from uint256, reverting on
   * overflow (when the input is greater than largest uint104).
   *
   * Counterpart to Solidity's `uint104` operator.
   *
   * Requirements:
   *
   * - input must fit into 104 bits
   */
  function toUint104(uint256 value) internal pure returns (uint104) {
    require(value < 2**104, "SafeCast: value doesn\'t fit in 104 bits");
    return uint104(value);
  }

  /**
   * @dev Returns the downcasted uint96 from uint256, reverting on
   * overflow (when the input is greater than largest uint96).
   *
   * Counterpart to Solidity's `uint104` operator.
   *
   * Requirements:
   *
   * - input must fit into 96 bits
   */
  function toUint96(uint256 value) internal pure returns (uint96) {
    require(value < 2**96, "SafeCast: value doesn\'t fit in 96 bits");
    return uint96(value);
  }

  /**
   * @dev Returns the downcasted uint88 from uint256, reverting on
   * overflow (when the input is greater than largest uint88).
   *
   * Counterpart to Solidity's `uint104` operator.
   *
   * Requirements:
   *
   * - input must fit into 88 bits
   */
  function toUint88(uint256 value) internal pure returns (uint88) {
    require(value < 2**88, "SafeCast: value doesn\'t fit in 88 bits");
    return uint88(value);
  }

  /**
   * @dev Returns the downcasted uint80 from uint256, reverting on
   * overflow (when the input is greater than largest uint80).
   *
   * Counterpart to Solidity's `uint104` operator.
   *
   * Requirements:
   *
   * - input must fit into 80 bits
   */
  function toUint80(uint256 value) internal pure returns (uint80) {
    require(value < 2**80, "SafeCast: value doesn\'t fit in 80 bits");
    return uint80(value);
  }

  /**
   * @dev Returns the downcasted uint64 from uint256, reverting on
   * overflow (when the input is greater than largest uint64).
   *
   * Counterpart to Solidity's `uint64` operator.
   *
   * Requirements:
   *
   * - input must fit into 64 bits
   */
  function toUint64(uint256 value) internal pure returns (uint64) {
    require(value < 2**64, "SafeCast: value doesn\'t fit in 64 bits");
    return uint64(value);
  }

  /**
   * @dev Returns the downcasted uint56 from uint256, reverting on
   * overflow (when the input is greater than largest uint56).
   *
   * Counterpart to Solidity's `uint56` operator.
   *
   * Requirements:
   *
   * - input must fit into 56 bits
   */
  function toUint56(uint256 value) internal pure returns (uint56) {
    require(value < 2**56, "SafeCast: value doesn\'t fit in 56 bits");
    return uint56(value);
  }

  /**
   * @dev Returns the downcasted uint48 from uint256, reverting on
   * overflow (when the input is greater than largest uint48).
   *
   * Counterpart to Solidity's `uint48` operator.
   *
   * Requirements:
   *
   * - input must fit into 48 bits
   */
  function toUint48(uint256 value) internal pure returns (uint48) {
    require(value < 2**48, "SafeCast: value doesn\'t fit in 48 bits");
    return uint48(value);
  }

  /**
   * @dev Returns the downcasted uint40 from uint256, reverting on
   * overflow (when the input is greater than largest uint40).
   *
   * Counterpart to Solidity's `uint40` operator.
   *
   * Requirements:
   *
   * - input must fit into 40 bits
   */
  function toUint40(uint256 value) internal pure returns (uint40) {
    require(value < 2**40, "SafeCast: value doesn\'t fit in 40 bits");
    return uint40(value);
  }

  /**
   * @dev Returns the downcasted uint32 from uint256, reverting on
   * overflow (when the input is greater than largest uint32).
   *
   * Counterpart to Solidity's `uint32` operator.
   *
   * Requirements:
   *
   * - input must fit into 32 bits
   */
  function toUint32(uint256 value) internal pure returns (uint32) {
    require(value < 2**32, "SafeCast: value doesn\'t fit in 32 bits");
    return uint32(value);
  }

  /**
   * @dev Returns the downcasted uint24 from uint256, reverting on
   * overflow (when the input is greater than largest uint24).
   *
   * Counterpart to Solidity's `uint24` operator.
   *
   * Requirements:
   *
   * - input must fit into 24 bits
   */
  function toUint24(uint256 value) internal pure returns (uint24) {
    require(value < 2**24, "SafeCast: value doesn\'t fit in 24 bits");
    return uint24(value);
  }

  /**
   * @dev Returns the downcasted uint16 from uint256, reverting on
   * overflow (when the input is greater than largest uint16).
   *
   * Counterpart to Solidity's `uint16` operator.
   *
   * Requirements:
   *
   * - input must fit into 16 bits
   */
  function toUint16(uint256 value) internal pure returns (uint16) {
    require(value < 2**16, "SafeCast: value doesn\'t fit in 16 bits");
    return uint16(value);
  }

  /**
   * @dev Returns the downcasted uint8 from uint256, reverting on
   * overflow (when the input is greater than largest uint8).
   *
   * Counterpart to Solidity's `uint8` operator.
   *
   * Requirements:
   *
   * - input must fit into 8 bits.
   */
  function toUint8(uint256 value) internal pure returns (uint8) {
    require(value < 2**8, "SafeCast: value doesn\'t fit in 8 bits");
    return uint8(value);
  }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "prague"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.