ETH Price: $3,295.66 (+0.98%)

Contract

0x0000cbD7a26f72Ff222bf5f136901D224b08BE4E
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Buy Cover214639982024-12-23 8:29:4728 days ago1734942587IN
0x0000cbD7...24b08BE4E
0.00363001 ETH0.005527585.59485721
Buy Cover214461842024-12-20 20:41:2331 days ago1734727283IN
0x0000cbD7...24b08BE4E
0 ETH0.0009535914.17164965
Buy Cover214461472024-12-20 20:33:5931 days ago1734726839IN
0x0000cbD7...24b08BE4E
0 ETH0.001051115.62077957
Buy Cover213851052024-12-12 8:02:5939 days ago1733990579IN
0x0000cbD7...24b08BE4E
0.01650383 ETH0.0153834914.91520131
Buy Cover212870852024-11-28 15:27:1153 days ago1732807631IN
0x0000cbD7...24b08BE4E
0.00009077 ETH0.0161452516.12859726
Buy Cover210130122024-10-21 9:19:2391 days ago1729502363IN
0x0000cbD7...24b08BE4E
0.00548623 ETH0.008599619.77107922
Buy Cover210130022024-10-21 9:17:2391 days ago1729502243IN
0x0000cbD7...24b08BE4E
0.00542244 ETH0.009401649.71107761
Buy Cover206305492024-08-29 0:04:35144 days ago1724889875IN
0x0000cbD7...24b08BE4E
0.00138291 ETH0.001045231.13577536
Buy Cover206305222024-08-28 23:59:11144 days ago1724889551IN
0x0000cbD7...24b08BE4E
0.00957167 ETH0.000864540.93337234
Buy Cover206305172024-08-28 23:58:11144 days ago1724889491IN
0x0000cbD7...24b08BE4E
0.00645354 ETH0.001111391.12849349
Buy Cover205420392024-08-16 15:18:23157 days ago1723821503IN
0x0000cbD7...24b08BE4E
0.00029408 ETH0.001495911.63593083
Buy Cover205219182024-08-13 19:53:47160 days ago1723578827IN
0x0000cbD7...24b08BE4E
0.01645508 ETH0.00253752.78403199
Buy Cover204967512024-08-10 7:34:59163 days ago1723275299IN
0x0000cbD7...24b08BE4E
0.00164612 ETH0.001301441.39782054
Buy Cover204828032024-08-08 8:54:47165 days ago1723107287IN
0x0000cbD7...24b08BE4E
0.31323842 ETH0.002370431.92887964
Buy Cover204826862024-08-08 8:31:23165 days ago1723105883IN
0x0000cbD7...24b08BE4E
0.03291052 ETH0.002088672.28703656
Buy Cover204340212024-08-01 13:33:35172 days ago1722519215IN
0x0000cbD7...24b08BE4E
0.08293283 ETH0.0145631415.36532261
Buy Cover203957352024-07-27 5:16:35177 days ago1722057395IN
0x0000cbD7...24b08BE4E
0.00307204 ETH0.001939852.12862053
Buy Cover203895982024-07-26 8:41:59178 days ago1721983319IN
0x0000cbD7...24b08BE4E
0.07078052 ETH0.00307693.31198905
Buy Cover201899292024-06-28 11:37:11206 days ago1719574631IN
0x0000cbD7...24b08BE4E
0.00435261 ETH0.004733834.02115031
Buy Cover201503672024-06-22 22:57:59211 days ago1719097079IN
0x0000cbD7...24b08BE4E
0.00191819 ETH0.001423891.55341489
Buy Cover201407292024-06-21 14:35:11213 days ago1718980511IN
0x0000cbD7...24b08BE4E
0.01646338 ETH0.0092851911.26219703
Buy Cover201407272024-06-21 14:34:47213 days ago1718980487IN
0x0000cbD7...24b08BE4E
0.00410411 ETH0.010998812.48077107
Buy Cover200653012024-06-11 1:27:35223 days ago1718069255IN
0x0000cbD7...24b08BE4E
0.00840337 ETH0.003977984.60797929
Buy Cover200652972024-06-11 1:26:47223 days ago1718069207IN
0x0000cbD7...24b08BE4E
0.00820975 ETH0.003763384.55771574
Buy Cover200652952024-06-11 1:26:23223 days ago1718069183IN
0x0000cbD7...24b08BE4E
0.00820975 ETH0.004000344.37435432
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
214639982024-12-23 8:29:4728 days ago1734942587
0x0000cbD7...24b08BE4E
0.00000351 ETH
214639982024-12-23 8:29:4728 days ago1734942587
0x0000cbD7...24b08BE4E
0.00000351 ETH
214639982024-12-23 8:29:4728 days ago1734942587
0x0000cbD7...24b08BE4E
0.00363001 ETH
213851052024-12-12 8:02:5939 days ago1733990579
0x0000cbD7...24b08BE4E
0.00001597 ETH
213851052024-12-12 8:02:5939 days ago1733990579
0x0000cbD7...24b08BE4E
0.00001597 ETH
213851052024-12-12 8:02:5939 days ago1733990579
0x0000cbD7...24b08BE4E
0.01650383 ETH
212870852024-11-28 15:27:1153 days ago1732807631
0x0000cbD7...24b08BE4E
0.00000025 ETH
212870852024-11-28 15:27:1153 days ago1732807631
0x0000cbD7...24b08BE4E
0.00000025 ETH
212870852024-11-28 15:27:1153 days ago1732807631
0x0000cbD7...24b08BE4E
0.00009077 ETH
210130122024-10-21 9:19:2391 days ago1729502363
0x0000cbD7...24b08BE4E
0.00000319 ETH
210130122024-10-21 9:19:2391 days ago1729502363
0x0000cbD7...24b08BE4E
0.00000319 ETH
210130122024-10-21 9:19:2391 days ago1729502363
0x0000cbD7...24b08BE4E
0.00548623 ETH
210130022024-10-21 9:17:2391 days ago1729502243
0x0000cbD7...24b08BE4E
0.00000316 ETH
210130022024-10-21 9:17:2391 days ago1729502243
0x0000cbD7...24b08BE4E
0.00000316 ETH
210130022024-10-21 9:17:2391 days ago1729502243
0x0000cbD7...24b08BE4E
0.00542244 ETH
206305492024-08-29 0:04:35144 days ago1724889875
0x0000cbD7...24b08BE4E
0.00000136 ETH
206305492024-08-29 0:04:35144 days ago1724889875
0x0000cbD7...24b08BE4E
0.00000136 ETH
206305492024-08-29 0:04:35144 days ago1724889875
0x0000cbD7...24b08BE4E
0.00138291 ETH
206305222024-08-28 23:59:11144 days ago1724889551
0x0000cbD7...24b08BE4E
0.00000929 ETH
206305222024-08-28 23:59:11144 days ago1724889551
0x0000cbD7...24b08BE4E
0.00000929 ETH
206305222024-08-28 23:59:11144 days ago1724889551
0x0000cbD7...24b08BE4E
0.00957167 ETH
206305172024-08-28 23:58:11144 days ago1724889491
0x0000cbD7...24b08BE4E
0.00000637 ETH
206305172024-08-28 23:58:11144 days ago1724889491
0x0000cbD7...24b08BE4E
0.00000637 ETH
206305172024-08-28 23:58:11144 days ago1724889491
0x0000cbD7...24b08BE4E
0.00645354 ETH
205420392024-08-16 15:18:23157 days ago1723821503
0x0000cbD7...24b08BE4E
0.00000027 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CoverBroker

Compiler Version
v0.8.18+commit.87f61d96

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 20 : CoverBroker.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.18;

import "@openzeppelin/contracts-v4/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-v4/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts-v4/access/Ownable.sol";

import "../../interfaces/ICover.sol";
import "../../interfaces/ICoverBroker.sol";
import "../../interfaces/IMemberRoles.sol";
import "../../interfaces/INXMMaster.sol";
import "../../interfaces/INXMToken.sol";
import "../../interfaces/IPool.sol";

/// @title Cover Broker Contract
/// @notice Enables non-members of the mutual to purchase cover policies.
/// Supports payments in ETH and pool supported ERC20 assets.
/// For NXM payments by members, please call Cover.buyCover instead.
/// @dev See supported ERC20 asset payments via pool.getAssets.
contract CoverBroker is ICoverBroker, Ownable {
  using SafeERC20 for IERC20;

  // Immutables
  ICover public immutable cover;
  IMemberRoles public immutable memberRoles;
  INXMToken public immutable nxmToken;
  INXMMaster public immutable master;

  // Constants
  address public constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
  uint private constant ETH_ASSET_ID = 0;
  uint private constant NXM_ASSET_ID = type(uint8).max;

  constructor(
    address _cover,
    address _memberRoles,
    address _nxmToken,
    address _master,
    address _owner
  ) {
    cover = ICover(_cover);
    memberRoles = IMemberRoles(_memberRoles);
    nxmToken = INXMToken(_nxmToken);
    master = INXMMaster(_master);
    transferOwnership(_owner);
  }

  /// @notice Buys cover on behalf of the caller. Supports payments in ETH and pool supported ERC20 assets.
  /// @dev For ERC20 payments, ensure the Cover contract is approved to spend the tokens first (maxApproveCoverContract).
  /// See supported ERC20 asset payments via pool.getAssets.
  /// @param params The parameters required to buy cover.
  /// @param poolAllocationRequests The allocation requests for the pool's liquidity.
  /// @return coverId The ID of the purchased cover.
  function buyCover(
    BuyCoverParams calldata params,
    PoolAllocationRequest[] calldata poolAllocationRequests
  ) external payable returns (uint coverId) {

    if (params.owner == address(0) || params.owner == address(this)) {
      revert InvalidOwnerAddress();
    }

    if (params.paymentAsset == NXM_ASSET_ID) {
      revert InvalidPaymentAsset();
    }

    // ETH payment
    if (params.paymentAsset == ETH_ASSET_ID) {
      return _buyCoverEthPayment(params, poolAllocationRequests);
    }

    // msg.value must be 0 if not an ETH payment
    if (msg.value > 0) {
      revert InvalidPayment();
    }

    // ERC20 payment
    return _buyCoverErc20Payment(params, poolAllocationRequests);
  }

  /// @notice Handles ETH payments for buying cover.
  /// @dev Calculates ETH refunds if applicable and sends back to msg.sender.
  /// @param params The parameters required to buy cover.
  /// @param poolAllocationRequests The allocation requests for the pool's liquidity.
  /// @return coverId The ID of the purchased cover.
  function _buyCoverEthPayment(
    BuyCoverParams calldata params,
    PoolAllocationRequest[] calldata poolAllocationRequests
  ) internal returns (uint coverId) {

    uint ethBalanceBefore = address(this).balance - msg.value;
    coverId = cover.buyCover{value: msg.value}(params, poolAllocationRequests);
    uint ethBalanceAfter = address(this).balance;

    // transfer any ETH refund back to msg.sender
    if (ethBalanceAfter > ethBalanceBefore) {
      uint ethRefund = ethBalanceAfter - ethBalanceBefore;
      (bool sent,) = payable(msg.sender).call{value: ethRefund}("");
      if (!sent) {
        revert TransferFailed(msg.sender, ethRefund, ETH);
      }
    }
  }

  /// @notice Handles ERC20 payments for buying cover.
  /// @dev Transfers ERC20 tokens from the caller to the contract, then buys cover on behalf of the caller.
  /// Calculates ERC20 refunds if any and sends back to msg.sender.
  /// @param params The parameters required to buy cover.
  /// @param poolAllocationRequests The allocation requests for the pool's liquidity.
  /// @return coverId The ID of the purchased cover.
  function _buyCoverErc20Payment(
    BuyCoverParams calldata params,
    PoolAllocationRequest[] calldata poolAllocationRequests
  ) internal returns (uint coverId) {

    address paymentAsset = _pool().getAsset(params.paymentAsset).assetAddress;
    IERC20 erc20 = IERC20(paymentAsset);

    uint erc20BalanceBefore = erc20.balanceOf(address(this));

    erc20.safeTransferFrom(msg.sender, address(this), params.maxPremiumInAsset);
    coverId = cover.buyCover(params, poolAllocationRequests);

    uint erc20BalanceAfter = erc20.balanceOf(address(this));

    // send any ERC20 refund back to msg.sender
    if (erc20BalanceAfter > erc20BalanceBefore) {
      uint erc20Refund = erc20BalanceAfter - erc20BalanceBefore;
      erc20.safeTransfer(msg.sender, erc20Refund);
    }
  }

  /// @notice Allows the Cover contract to spend the maximum possible amount of a specified ERC20 token on behalf of the CoverBroker.
  /// @param erc20 The ERC20 token for which to approve spending.
  function maxApproveCoverContract(IERC20 erc20) external onlyOwner {
    erc20.safeApprove(address(cover), type(uint256).max);
  }

  /// @notice Switches CoverBroker's membership to a new address.
  /// @dev MemberRoles contract needs to be approved to transfer NXM tokens to new membership address.
  /// @param newAddress The address to which the membership will be switched.
  function switchMembership(address newAddress) external onlyOwner {
    nxmToken.approve(address(memberRoles), type(uint256).max);
    memberRoles.switchMembership(newAddress);
  }

  /// @notice Recovers all available funds of a specified asset (ETH or ERC20) to the contract owner.
  /// @param assetAddress The address of the asset to be rescued.
  function rescueFunds(address assetAddress) external onlyOwner {

    if (assetAddress == ETH) {
      uint ethBalance = address(this).balance;
      if (ethBalance == 0) {
        revert ZeroBalance(ETH);
      }

      (bool sent,) = payable(msg.sender).call{value: ethBalance}("");
      if (!sent) {
        revert TransferFailed(msg.sender, ethBalance, ETH);
      }

      return;
    }

    IERC20 asset = IERC20(assetAddress);
    uint erc20Balance = asset.balanceOf(address(this));
    if (erc20Balance == 0) {
      revert ZeroBalance(assetAddress);
    }

    asset.transfer(msg.sender, erc20Balance);
  }

  /* ========== DEPENDENCIES ========== */

  /// @dev Fetches the Pool's instance through master contract
  /// @return The Pool's instance
  function _pool() internal view returns (IPool) {
    return IPool(master.getLatestAddress("P1"));
  }

  receive() external payable {}
}

File 2 of 20 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 3 of 20 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 4 of 20 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, 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 `from` to `to` 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 from,
        address to,
        uint256 amount
    ) external returns (bool);
}

File 5 of 20 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 6 of 20 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 7 of 20 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 8 of 20 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 9 of 20 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 10 of 20 : ICover.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "./ICoverNFT.sol";
import "./IStakingNFT.sol";
import "./IStakingPool.sol";
import "./IStakingPoolFactory.sol";

/* ========== DATA STRUCTURES ========== */

enum ClaimMethod {
  IndividualClaims,
  YieldTokenIncidents
}

// Basically CoverStatus from QuotationData.sol but with the extra Migrated status to avoid
// polluting Cover.sol state layout with new status variables.
enum LegacyCoverStatus {
  Active,
  ClaimAccepted,
  ClaimDenied,
  CoverExpired,
  ClaimSubmitted,
  Requested,
  Migrated
}

/* io structs */

struct PoolAllocationRequest {
  uint40 poolId;
  bool skip;
  uint coverAmountInAsset;
}

struct RequestAllocationVariables {
  uint previousPoolAllocationsLength;
  uint previousPremiumInNXM;
  uint refund;
  uint coverAmountInNXM;
}

struct BuyCoverParams {
  uint coverId;
  address owner;
  uint24 productId;
  uint8 coverAsset;
  uint96 amount;
  uint32 period;
  uint maxPremiumInAsset;
  uint8 paymentAsset;
  uint16 commissionRatio;
  address commissionDestination;
  string ipfsData;
}

struct ProductParam {
  string productName;
  uint productId;
  string ipfsMetadata;
  Product product;
  uint[] allowedPools;
}

struct ProductTypeParam {
  string productTypeName;
  uint productTypeId;
  string ipfsMetadata;
  ProductType productType;
}

struct ProductInitializationParams {
  uint productId;
  uint8 weight;
  uint96 initialPrice;
  uint96 targetPrice;
}

/* storage structs */

struct PoolAllocation {
  uint40 poolId;
  uint96 coverAmountInNXM;
  uint96 premiumInNXM;
  uint24 allocationId;
}

struct CoverData {
  uint24 productId;
  uint8 coverAsset;
  uint96 amountPaidOut;
}

struct CoverSegment {
  uint96 amount;
  uint32 start;
  uint32 period; // seconds
  uint32 gracePeriod; // seconds
  uint24 globalRewardsRatio;
  uint24 globalCapacityRatio;
}

struct Product {
  uint16 productType;
  address yieldTokenAddress;
  // cover assets bitmap. each bit represents whether the asset with
  // the index of that bit is enabled as a cover asset for this product
  uint32 coverAssets;
  uint16 initialPriceRatio;
  uint16 capacityReductionRatio;
  bool isDeprecated;
  bool useFixedPrice;
}

struct ProductType {
  uint8 claimMethod;
  uint32 gracePeriod;
}

struct ActiveCover {
  // Global active cover amount per asset.
  uint192 totalActiveCoverInAsset;
  // The last time activeCoverExpirationBuckets was updated
  uint64 lastBucketUpdateId;
}

interface ICover {

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

  function coverData(uint coverId) external view returns (CoverData memory);

  function coverDataCount() external view returns (uint);

  function coverSegmentsCount(uint coverId) external view returns (uint);

  function coverSegments(uint coverId) external view returns (CoverSegment[] memory);

  function coverSegmentWithRemainingAmount(
    uint coverId,
    uint segmentId
  ) external view returns (CoverSegment memory);

  function products(uint id) external view returns (Product memory);

  function productTypes(uint id) external view returns (ProductType memory);

  function stakingPool(uint index) external view returns (IStakingPool);

  function productNames(uint productId) external view returns (string memory);

  function productsCount() external view returns (uint);

  function productTypesCount() external view returns (uint);

  function totalActiveCoverInAsset(uint coverAsset) external view returns (uint);

  function globalCapacityRatio() external view returns (uint);

  function globalRewardsRatio() external view returns (uint);

  function getPriceAndCapacityRatios(uint[] calldata productIds) external view returns (
    uint _globalCapacityRatio,
    uint _globalMinPriceRatio,
    uint[] memory _initialPriceRatios,
    uint[] memory _capacityReductionRatios
  );

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

  function addLegacyCover(
    uint productId,
    uint coverAsset,
    uint amount,
    uint start,
    uint period,
    address newOwner
  ) external returns (uint coverId);

  function buyCover(
    BuyCoverParams calldata params,
    PoolAllocationRequest[] calldata coverChunkRequests
  ) external payable returns (uint coverId);

  function setProductTypes(ProductTypeParam[] calldata productTypes) external;

  function setProducts(ProductParam[] calldata params) external;

  function burnStake(
    uint coverId,
    uint segmentId,
    uint amount
  ) external returns (address coverOwner);

  function coverNFT() external returns (ICoverNFT);

  function stakingNFT() external returns (IStakingNFT);

  function stakingPoolFactory() external returns (IStakingPoolFactory);

  function createStakingPool(
    bool isPrivatePool,
    uint initialPoolFee,
    uint maxPoolFee,
    ProductInitializationParams[] calldata productInitParams,
    string calldata ipfsDescriptionHash
  ) external returns (uint poolId, address stakingPoolAddress);

  function isPoolAllowed(uint productId, uint poolId) external returns (bool);
  function requirePoolIsAllowed(uint[] calldata productIds, uint poolId) external view;

  /* ========== EVENTS ========== */

  event ProductSet(uint id, string ipfsMetadata);
  event ProductTypeSet(uint id, string ipfsMetadata);
  event CoverEdited(uint indexed coverId, uint indexed productId, uint indexed segmentId, address buyer, string ipfsMetadata);

  // Auth
  error OnlyMemberRolesCanOperateTransfer();
  error OnlyOwnerOrApproved();

  // Cover details
  error CoverPeriodTooShort();
  error CoverPeriodTooLong();
  error CoverOutsideOfTheGracePeriod();
  error CoverAmountIsZero();

  // Products
  error ProductDoesntExist();
  error ProductTypeNotFound();
  error ProductDoesntExistOrIsDeprecated();
  error InvalidProductType();
  error UnexpectedProductId();
  error PoolNotAllowedForThisProduct(uint productId);

  // Cover and payment assets
  error CoverAssetNotSupported();
  error InvalidPaymentAsset();
  error UnexpectedCoverAsset();
  error UnsupportedCoverAssets();
  error UnexpectedEthSent();
  error EditNotSupported();

  // Price & Commission
  error PriceExceedsMaxPremiumInAsset();
  error TargetPriceBelowGlobalMinPriceRatio();
  error InitialPriceRatioBelowGlobalMinPriceRatio();
  error InitialPriceRatioAbove100Percent();
  error CommissionRateTooHigh();

  // ETH transfers
  error InsufficientEthSent();
  error SendingEthToPoolFailed();
  error SendingEthToCommissionDestinationFailed();
  error ReturningEthRemainderToSenderFailed();

  // Misc
  error AlreadyInitialized();
  error ExpiredCoversCannotBeEdited();
  error CoverNotYetExpired(uint coverId);
  error CoverAlreadyExpired(uint coverId);
  error InsufficientCoverAmountAllocated();
  error UnexpectedPoolId();
  error CapacityReductionRatioAbove100Percent();
}

File 11 of 20 : ICoverBroker.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.18;

import "@openzeppelin/contracts-v4/token/ERC20/IERC20.sol";

import "../interfaces/ICover.sol";

interface ICoverBroker {

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

  function buyCover(
    BuyCoverParams calldata params,
    PoolAllocationRequest[] calldata poolAllocationRequests
  ) external payable returns (uint coverId);

  function maxApproveCoverContract(IERC20 token) external;

  function switchMembership(address newAddress) external;

  function rescueFunds(address assetAddress) external;

  /* ==== ERRORS ==== */

  error TransferFailed(address to, uint value, address token);
  error ZeroBalance(address token);
  error InvalidOwnerAddress();
  error InvalidPaymentAsset();
  error InvalidPayment();
}

File 12 of 20 : ICoverNFT.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "@openzeppelin/contracts-v4/token/ERC721/IERC721.sol";

interface ICoverNFT is IERC721 {

  function isApprovedOrOwner(address spender, uint tokenId) external returns (bool);

  function mint(address to) external returns (uint tokenId);

  function changeOperator(address newOperator) external;

  function totalSupply() external view returns (uint);

  function name() external view returns (string memory);

  error NotOperator();
  error NotMinted();
  error WrongFrom();
  error InvalidRecipient();
  error InvalidNewOperatorAddress();
  error InvalidNewNFTDescriptorAddress();
  error NotAuthorized();
  error UnsafeRecipient();
  error AlreadyMinted();

}

File 13 of 20 : IMemberRoles.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface IMemberRoles {

  enum Role {Unassigned, AdvisoryBoard, Member, Owner}

  function join(address _userAddress, uint nonce, bytes calldata signature) external payable;

  function switchMembership(address _newAddress) external;

  function switchMembershipAndAssets(
    address newAddress,
    uint[] calldata coverIds,
    uint[] calldata stakingTokenIds
  ) external;

  function switchMembershipOf(address member, address _newAddress) external;

  function totalRoles() external view returns (uint256);

  function changeAuthorized(uint _roleId, address _newAuthorized) external;

  function setKycAuthAddress(address _add) external;

  function members(uint _memberRoleId) external view returns (uint, address[] memory memberArray);

  function numberOfMembers(uint _memberRoleId) external view returns (uint);

  function authorized(uint _memberRoleId) external view returns (address);

  function roles(address _memberAddress) external view returns (uint[] memory);

  function checkRole(address _memberAddress, uint _roleId) external view returns (bool);

  function getMemberLengthForAllRoles() external view returns (uint[] memory totalMembers);

  function memberAtIndex(uint _memberRoleId, uint index) external view returns (address, bool);

  function membersLength(uint _memberRoleId) external view returns (uint);

  event MemberRole(uint256 indexed roleId, bytes32 roleName, string roleDescription);

  event MemberJoined(address indexed newMember, uint indexed nonce);

  event switchedMembership(address indexed previousMember, address indexed newMember, uint timeStamp);
  
  event MembershipWithdrawn(address indexed member, uint timestamp);
}

File 14 of 20 : INXMMaster.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface INXMMaster {

  function tokenAddress() external view returns (address);

  function owner() external view returns (address);

  function emergencyAdmin() external view returns (address);

  function masterInitialized() external view returns (bool);

  function isInternal(address _add) external view returns (bool);

  function isPause() external view returns (bool check);

  function isMember(address _add) external view returns (bool);

  function checkIsAuthToGoverned(address _add) external view returns (bool);

  function getLatestAddress(bytes2 _contractName) external view returns (address payable contractAddress);

  function contractAddresses(bytes2 code) external view returns (address payable);

  function upgradeMultipleContracts(
    bytes2[] calldata _contractCodes,
    address payable[] calldata newAddresses
  ) external;

  function removeContracts(bytes2[] calldata contractCodesToRemove) external;

  function addNewInternalContracts(
    bytes2[] calldata _contractCodes,
    address payable[] calldata newAddresses,
    uint[] calldata _types
  ) external;

  function updateOwnerParameters(bytes8 code, address payable val) external;
}

File 15 of 20 : 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);
}

File 16 of 20 : IPool.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "./IPriceFeedOracle.sol";

struct SwapDetails {
  uint104 minAmount;
  uint104 maxAmount;
  uint32 lastSwapTime;
  // 2 decimals of precision. 0.01% -> 0.0001 -> 1e14
  uint16 maxSlippageRatio;
}

struct Asset {
  address assetAddress;
  bool isCoverAsset;
  bool isAbandoned;
}

interface IPool {

  function getAsset(uint assetId) external view returns (Asset memory);

  function getAssets() external view returns (Asset[] memory);

  function transferAssetToSwapOperator(address asset, uint amount) external;

  function setSwapDetailsLastSwapTime(address asset, uint32 lastSwapTime) external;

  function getAssetSwapDetails(address assetAddress) external view returns (SwapDetails memory);

  function sendPayout(uint assetIndex, address payable payoutAddress, uint amount, uint ethDepositAmount) external;

  function sendEth(address payoutAddress, uint amount) external;

  function upgradeCapitalPool(address payable newPoolAddress) external;

  function priceFeedOracle() external view returns (IPriceFeedOracle);

  function getPoolValueInEth() external view returns (uint);

  function calculateMCRRatio(uint totalAssetValue, uint mcrEth) external pure returns (uint);

  function getInternalTokenPriceInAsset(uint assetId) external view returns (uint tokenPrice);

  function getInternalTokenPriceInAssetAndUpdateTwap(uint assetId) external returns (uint tokenPrice);

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

  function getMCRRatio() external view returns (uint);

  function setSwapValue(uint value) external;
}

File 17 of 20 : IPriceFeedOracle.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface Aggregator {
  function latestAnswer() external view returns (int);
}

struct OracleAsset {
  Aggregator aggregator;
  uint8 decimals;
}

interface IPriceFeedOracle {

  function ETH() external view returns (address);
  function assets(address) external view returns (Aggregator, uint8);

  function getAssetToEthRate(address asset) external view returns (uint);
  function getAssetForEth(address asset, uint ethIn) external view returns (uint);
  function getEthForAsset(address asset, uint amount) external view returns (uint);

}

File 18 of 20 : IStakingNFT.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "@openzeppelin/contracts-v4/token/ERC721/IERC721.sol";

interface IStakingNFT is IERC721 {

  function isApprovedOrOwner(address spender, uint tokenId) external returns (bool);

  function mint(uint poolId, address to) external returns (uint tokenId);

  function changeOperator(address newOperator) external;

  function totalSupply() external returns (uint);

  function tokenInfo(uint tokenId) external view returns (uint poolId, address owner);

  function stakingPoolOf(uint tokenId) external view returns (uint poolId);

  function stakingPoolFactory() external view returns (address);

  function name() external view returns (string memory);

  error NotOperator();
  error NotMinted();
  error WrongFrom();
  error InvalidRecipient();
  error InvalidNewOperatorAddress();
  error InvalidNewNFTDescriptorAddress();
  error NotAuthorized();
  error UnsafeRecipient();
  error AlreadyMinted();
  error NotStakingPool();

}

File 19 of 20 : IStakingPool.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

/* structs for io */

struct AllocationRequest {
  uint productId;
  uint coverId;
  uint allocationId;
  uint period;
  uint gracePeriod;
  bool useFixedPrice;
  uint previousStart;
  uint previousExpiration;
  uint previousRewardsRatio;
  uint globalCapacityRatio;
  uint capacityReductionRatio;
  uint rewardRatio;
  uint globalMinPrice;
}

struct StakedProductParam {
  uint productId;
  bool recalculateEffectiveWeight;
  bool setTargetWeight;
  uint8 targetWeight;
  bool setTargetPrice;
  uint96 targetPrice;
}

  struct BurnStakeParams {
    uint allocationId;
    uint productId;
    uint start;
    uint period;
    uint deallocationAmount;
  }

interface IStakingPool {

  /* structs for storage */

  // stakers are grouped in tranches based on the timelock expiration
  // tranche index is calculated based on the expiration date
  // the initial proposal is to have 4 tranches per year (1 tranche per quarter)
  struct Tranche {
    uint128 stakeShares;
    uint128 rewardsShares;
  }

  struct ExpiredTranche {
    uint96 accNxmPerRewardShareAtExpiry;
    uint96 stakeAmountAtExpiry; // nxm total supply is 6.7e24 and uint96.max is 7.9e28
    uint128 stakeSharesSupplyAtExpiry;
  }

  struct Deposit {
    uint96 lastAccNxmPerRewardShare;
    uint96 pendingRewards;
    uint128 stakeShares;
    uint128 rewardsShares;
  }

  function initialize(
    bool isPrivatePool,
    uint initialPoolFee,
    uint maxPoolFee,
    uint _poolId,
    string memory ipfsDescriptionHash
  ) external;

  function processExpirations(bool updateUntilCurrentTimestamp) external;

  function requestAllocation(
    uint amount,
    uint previousPremium,
    AllocationRequest calldata request
  ) external returns (uint premium, uint allocationId);

  function burnStake(uint amount, BurnStakeParams calldata params) external;

  function depositTo(
    uint amount,
    uint trancheId,
    uint requestTokenId,
    address destination
  ) external returns (uint tokenId);

  function withdraw(
    uint tokenId,
    bool withdrawStake,
    bool withdrawRewards,
    uint[] memory trancheIds
  ) external returns (uint withdrawnStake, uint withdrawnRewards);

  function isPrivatePool() external view returns (bool);

  function isHalted() external view returns (bool);

  function manager() external view returns (address);

  function getPoolId() external view returns (uint);

  function getPoolFee() external view returns (uint);

  function getMaxPoolFee() external view returns (uint);

  function getActiveStake() external view returns (uint);

  function getStakeSharesSupply() external view returns (uint);

  function getRewardsSharesSupply() external view returns (uint);

  function getRewardPerSecond() external view returns (uint);

  function getAccNxmPerRewardsShare() external view returns (uint);

  function getLastAccNxmUpdate() external view returns (uint);

  function getFirstActiveTrancheId() external view returns (uint);

  function getFirstActiveBucketId() external view returns (uint);

  function getNextAllocationId() external view returns (uint);

  function getDeposit(uint tokenId, uint trancheId) external view returns (
    uint lastAccNxmPerRewardShare,
    uint pendingRewards,
    uint stakeShares,
    uint rewardsShares
  );

  function getTranche(uint trancheId) external view returns (
    uint stakeShares,
    uint rewardsShares
  );

  function getExpiredTranche(uint trancheId) external view returns (
    uint accNxmPerRewardShareAtExpiry,
    uint stakeAmountAtExpiry,
    uint stakeShareSupplyAtExpiry
  );

  function setPoolFee(uint newFee) external;

  function setPoolPrivacy(bool isPrivatePool) external;

  function getActiveAllocations(
    uint productId
  ) external view returns (uint[] memory trancheAllocations);

  function getTrancheCapacities(
    uint productId,
    uint firstTrancheId,
    uint trancheCount,
    uint capacityRatio,
    uint reductionRatio
  ) external view returns (uint[] memory trancheCapacities);

  /* ========== EVENTS ========== */

  event StakeDeposited(address indexed user, uint256 amount, uint256 trancheId, uint256 tokenId);

  event DepositExtended(address indexed user, uint256 tokenId, uint256 initialTrancheId, uint256 newTrancheId, uint256 topUpAmount);

  event PoolPrivacyChanged(address indexed manager, bool isPrivate);

  event PoolFeeChanged(address indexed manager, uint newFee);

  event PoolDescriptionSet(string ipfsDescriptionHash);

  event Withdraw(address indexed user, uint indexed tokenId, uint tranche, uint amountStakeWithdrawn, uint amountRewardsWithdrawn);

  event StakeBurned(uint amount);

  event Deallocated(uint productId);

  event BucketExpired(uint bucketId);

  event TrancheExpired(uint trancheId);

  // Auth
  error OnlyCoverContract();
  error OnlyManager();
  error PrivatePool();
  error SystemPaused();
  error PoolHalted();

  // Fees
  error PoolFeeExceedsMax();
  error MaxPoolFeeAbove100();

  // Voting
  error NxmIsLockedForGovernanceVote();
  error ManagerNxmIsLockedForGovernanceVote();

  // Deposit
  error InsufficientDepositAmount();
  error RewardRatioTooHigh();

  // Staking NFTs
  error InvalidTokenId();
  error NotTokenOwnerOrApproved();
  error InvalidStakingPoolForToken();

  // Tranche & capacity
  error NewTrancheEndsBeforeInitialTranche();
  error RequestedTrancheIsNotYetActive();
  error RequestedTrancheIsExpired();
  error InsufficientCapacity();

  // Allocation
  error AlreadyDeallocated(uint allocationId);
}

File 20 of 20 : IStakingPoolFactory.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface IStakingPoolFactory {

  function stakingPoolCount() external view returns (uint);

  function beacon() external view returns (address);

  function create(address beacon) external returns (uint poolId, address stakingPoolAddress);

  event StakingPoolCreated(uint indexed poolId, address indexed stakingPoolAddress);
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_cover","type":"address"},{"internalType":"address","name":"_memberRoles","type":"address"},{"internalType":"address","name":"_nxmToken","type":"address"},{"internalType":"address","name":"_master","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidOwnerAddress","type":"error"},{"inputs":[],"name":"InvalidPayment","type":"error"},{"inputs":[],"name":"InvalidPaymentAsset","type":"error"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"address","name":"token","type":"address"}],"name":"TransferFailed","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"ZeroBalance","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"ETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"coverId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint24","name":"productId","type":"uint24"},{"internalType":"uint8","name":"coverAsset","type":"uint8"},{"internalType":"uint96","name":"amount","type":"uint96"},{"internalType":"uint32","name":"period","type":"uint32"},{"internalType":"uint256","name":"maxPremiumInAsset","type":"uint256"},{"internalType":"uint8","name":"paymentAsset","type":"uint8"},{"internalType":"uint16","name":"commissionRatio","type":"uint16"},{"internalType":"address","name":"commissionDestination","type":"address"},{"internalType":"string","name":"ipfsData","type":"string"}],"internalType":"struct BuyCoverParams","name":"params","type":"tuple"},{"components":[{"internalType":"uint40","name":"poolId","type":"uint40"},{"internalType":"bool","name":"skip","type":"bool"},{"internalType":"uint256","name":"coverAmountInAsset","type":"uint256"}],"internalType":"struct PoolAllocationRequest[]","name":"poolAllocationRequests","type":"tuple[]"}],"name":"buyCover","outputs":[{"internalType":"uint256","name":"coverId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"cover","outputs":[{"internalType":"contract ICover","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"master","outputs":[{"internalType":"contract INXMMaster","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"erc20","type":"address"}],"name":"maxApproveCoverContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"memberRoles","outputs":[{"internalType":"contract IMemberRoles","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nxmToken","outputs":[{"internalType":"contract INXMToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"assetAddress","type":"address"}],"name":"rescueFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAddress","type":"address"}],"name":"switchMembership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

6101006040523480156200001257600080fd5b50604051620017f7380380620017f78339810160408190526200003591620001c3565b620000403362000075565b6001600160a01b0380861660805284811660a05283811660c052821660e0526200006a81620000c5565b505050505062000233565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b620000cf62000148565b6001600160a01b0381166200013a5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084015b60405180910390fd5b620001458162000075565b50565b6000546001600160a01b03163314620001a45760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640162000131565b565b80516001600160a01b0381168114620001be57600080fd5b919050565b600080600080600060a08688031215620001dc57600080fd5b620001e786620001a6565b9450620001f760208701620001a6565b93506200020760408701620001a6565b92506200021760608701620001a6565b91506200022760808701620001a6565b90509295509295909350565b60805160a05160c05160e05161155a6200029d6000396000818161023f0152610e2e01526000818161020b015261033201526000818160c90152818161030201526103bf0152600081816101d7015281816102b9015281816109ab0152610c1e015261155a6000f3fe6080604052600436106100ab5760003560e01c8063e53b201711610064578063e53b2017146101a5578063e7d931e4146101c5578063e967eb1a146101f9578063ee97f7f31461022d578063f2fde38b14610261578063f65796321461028157600080fd5b80630bd92b3b146100b75780631c7cab59146101085780634ed75d471461012a578063715018a61461014a5780638322fff21461015f5780638da5cb5b1461018757600080fd5b366100b257005b600080fd5b3480156100c357600080fd5b506100eb7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561011457600080fd5b50610128610123366004611037565b6102a2565b005b34801561013657600080fd5b50610128610145366004611037565b6102e3565b34801561015657600080fd5b5061012861041e565b34801561016b57600080fd5b506100eb73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b34801561019357600080fd5b506000546001600160a01b03166100eb565b3480156101b157600080fd5b506101286101c0366004611037565b610432565b3480156101d157600080fd5b506100eb7f000000000000000000000000000000000000000000000000000000000000000081565b34801561020557600080fd5b506100eb7f000000000000000000000000000000000000000000000000000000000000000081565b34801561023957600080fd5b506100eb7f000000000000000000000000000000000000000000000000000000000000000081565b34801561026d57600080fd5b5061012861027c366004611037565b610640565b61029461028f366004611064565b6106b6565b6040519081526020016100ff565b6102aa6107a8565b6102e06001600160a01b0382167f0000000000000000000000000000000000000000000000000000000000000000600019610802565b50565b6102eb6107a8565b60405163095ea7b360e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260001960248301527f0000000000000000000000000000000000000000000000000000000000000000169063095ea7b3906044016020604051808303816000875af115801561037b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061039f9190611115565b50604051634ed75d4760e01b81526001600160a01b0382811660048301527f00000000000000000000000000000000000000000000000000000000000000001690634ed75d4790602401600060405180830381600087803b15801561040357600080fd5b505af1158015610417573d6000803e3d6000fd5b5050505050565b6104266107a8565b610430600061094a565b565b61043a6107a8565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b0382160161052e5747600081900361049d576040516316b4356760e31b815273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee60048201526024015b60405180910390fd5b604051600090339083908381818185875af1925050503d80600081146104df576040519150601f19603f3d011682016040523d82523d6000602084013e6104e4565b606091505b50509050806105295760405163ba1109b360e01b81523360048201526024810183905273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6044820152606401610494565b505050565b6040516370a0823160e01b815230600482015281906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610577573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059b9190611132565b9050806000036105c9576040516316b4356760e31b81526001600160a01b0384166004820152602401610494565b60405163a9059cbb60e01b8152336004820152602481018290526001600160a01b0383169063a9059cbb906044016020604051808303816000875af1158015610616573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063a9190611115565b50505050565b6106486107a8565b6001600160a01b0381166106ad5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610494565b6102e08161094a565b6000806106c96040860160208701611037565b6001600160a01b031614806106f55750306106ea6040860160208701611037565b6001600160a01b0316145b1561071357604051633649397d60e21b815260040160405180910390fd5b60ff610726610100860160e0870161115c565b60ff1603610747576040516304b4a0b760e51b815260040160405180910390fd5b600061075a610100860160e0870161115c565b60ff16036107745761076d84848461099a565b90506107a1565b34156107935760405163078d696560e31b815260040160405180910390fd5b61079e848484610aef565b90505b9392505050565b6000546001600160a01b031633146104305760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610494565b80158061087c5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015610856573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061087a9190611132565b155b6108e75760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610494565b6040516001600160a01b03831660248201526044810182905261052990849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152610d40565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000806109a73447611177565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f6579632348787876040518563ffffffff1660e01b81526004016109fa939291906112d5565b60206040518083038185885af1158015610a18573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610a3d9190611132565b91504781811115610ae6576000610a548383611177565b604051909150600090339083908381818185875af1925050503d8060008114610a99576040519150601f19603f3d011682016040523d82523d6000602084013e610a9e565b606091505b5050905080610ae35760405163ba1109b360e01b81523360048201526024810183905273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6044820152606401610494565b50505b50509392505050565b600080610afa610e12565b6001600160a01b031663eac8f5b8610b19610100880160e0890161115c565b6040516001600160e01b031960e084901b16815260ff9091166004820152602401606060405180830381865afa158015610b57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b7b9190611414565b516040516370a0823160e01b815230600482015290915081906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610bc8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bec9190611132565b9050610c076001600160a01b038316333060c08b0135610ea6565b604051637b2bcb1960e11b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063f657963290610c57908a908a908a906004016112d5565b6020604051808303816000875af1158015610c76573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c9a9190611132565b6040516370a0823160e01b81523060048201529094506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610ce4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d089190611132565b905081811115610ae3576000610d1e8383611177565b9050610d346001600160a01b0385163383610ede565b50505050509392505050565b6000610d95826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610f0e9092919063ffffffff16565b8051909150156105295780806020019051810190610db39190611115565b6105295760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610494565b6040516227050b60e31b815261503160f01b60048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690630138285890602401602060405180830381865afa158015610e7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ea19190611494565b905090565b6040516001600160a01b038085166024830152831660448201526064810182905261063a9085906323b872dd60e01b90608401610913565b6040516001600160a01b03831660248201526044810182905261052990849063a9059cbb60e01b90606401610913565b606061079e8484600085856001600160a01b0385163b610f705760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610494565b600080866001600160a01b03168587604051610f8c91906114d5565b60006040518083038185875af1925050503d8060008114610fc9576040519150601f19603f3d011682016040523d82523d6000602084013e610fce565b606091505b5091509150610fde828286610fe9565b979650505050505050565b60608315610ff85750816107a1565b8251156110085782518084602001fd5b8160405162461bcd60e51b815260040161049491906114f1565b6001600160a01b03811681146102e057600080fd5b60006020828403121561104957600080fd5b81356107a181611022565b803561105f81611022565b919050565b60008060006040848603121561107957600080fd5b833567ffffffffffffffff8082111561109157600080fd5b9085019061016082880312156110a657600080fd5b909350602085013590808211156110bc57600080fd5b818601915086601f8301126110d057600080fd5b8135818111156110df57600080fd5b8760206060830285010111156110f457600080fd5b6020830194508093505050509250925092565b80151581146102e057600080fd5b60006020828403121561112757600080fd5b81516107a181611107565b60006020828403121561114457600080fd5b5051919050565b803560ff8116811461105f57600080fd5b60006020828403121561116e57600080fd5b6107a18261114b565b8181038181111561119857634e487b7160e01b600052601160045260246000fd5b92915050565b803562ffffff8116811461105f57600080fd5b80356bffffffffffffffffffffffff8116811461105f57600080fd5b803563ffffffff8116811461105f57600080fd5b803561ffff8116811461105f57600080fd5b6000808335601e1984360301811261120a57600080fd5b830160208101925035905067ffffffffffffffff81111561122a57600080fd5b80360382131561123957600080fd5b9250929050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b818352600060208085019450826000805b868110156112c957823564ffffffffff8116808214611297578384fd5b895250828401356112a781611107565b151588850152604083810135908901526060978801979092019160010161127a565b50959695505050505050565b604081528335604082015260006112ee60208601611054565b6001600160a01b031660608301526113086040860161119e565b62ffffff16608083015261131e6060860161114b565b60ff1660a0830152611332608086016111b1565b6bffffffffffffffffffffffff1660c083015261135160a086016111cd565b63ffffffff811660e08401525061010060c08601358184015261137660e0870161114b565b6101206113878186018360ff169052565b6113928389016111e1565b925061014091506113a88286018461ffff169052565b6113b3818901611054565b9250506101606113cd818601846001600160a01b03169052565b6113d9828901896111f3565b9350915080610180860152506113f46101a085018383611240565b915050828103602084015261140a818587611269565b9695505050505050565b60006060828403121561142657600080fd5b6040516060810181811067ffffffffffffffff8211171561145757634e487b7160e01b600052604160045260246000fd5b604052825161146581611022565b8152602083015161147581611107565b6020820152604083015161148881611107565b60408201529392505050565b6000602082840312156114a657600080fd5b81516107a181611022565b60005b838110156114cc5781810151838201526020016114b4565b50506000910152565b600082516114e78184602087016114b1565b9190910192915050565b60208152600082518060208401526115108160408501602087016114b1565b601f01601f1916919091016040019291505056fea2646970667358221220593d74b7d681a037a54295bb24ae6ba8ce9f2820866ab4e44d4f5c41c32d193b64736f6c63430008120033000000000000000000000000cafeac0ff5da0a2777d915531bfa6b29d282ee62000000000000000000000000055cc48f7968fd8640ef140610dd4038e1b03926000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b00000000000000000000000001bfd82675dbcc7762c84019ca518e701c0cd07e00000000000000000000000046842a7d9372bb7dba08f0729393deda230a03b5

Deployed Bytecode

0x6080604052600436106100ab5760003560e01c8063e53b201711610064578063e53b2017146101a5578063e7d931e4146101c5578063e967eb1a146101f9578063ee97f7f31461022d578063f2fde38b14610261578063f65796321461028157600080fd5b80630bd92b3b146100b75780631c7cab59146101085780634ed75d471461012a578063715018a61461014a5780638322fff21461015f5780638da5cb5b1461018757600080fd5b366100b257005b600080fd5b3480156100c357600080fd5b506100eb7f000000000000000000000000055cc48f7968fd8640ef140610dd4038e1b0392681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561011457600080fd5b50610128610123366004611037565b6102a2565b005b34801561013657600080fd5b50610128610145366004611037565b6102e3565b34801561015657600080fd5b5061012861041e565b34801561016b57600080fd5b506100eb73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b34801561019357600080fd5b506000546001600160a01b03166100eb565b3480156101b157600080fd5b506101286101c0366004611037565b610432565b3480156101d157600080fd5b506100eb7f000000000000000000000000cafeac0ff5da0a2777d915531bfa6b29d282ee6281565b34801561020557600080fd5b506100eb7f000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b81565b34801561023957600080fd5b506100eb7f00000000000000000000000001bfd82675dbcc7762c84019ca518e701c0cd07e81565b34801561026d57600080fd5b5061012861027c366004611037565b610640565b61029461028f366004611064565b6106b6565b6040519081526020016100ff565b6102aa6107a8565b6102e06001600160a01b0382167f000000000000000000000000cafeac0ff5da0a2777d915531bfa6b29d282ee62600019610802565b50565b6102eb6107a8565b60405163095ea7b360e01b81526001600160a01b037f000000000000000000000000055cc48f7968fd8640ef140610dd4038e1b039268116600483015260001960248301527f000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b169063095ea7b3906044016020604051808303816000875af115801561037b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061039f9190611115565b50604051634ed75d4760e01b81526001600160a01b0382811660048301527f000000000000000000000000055cc48f7968fd8640ef140610dd4038e1b039261690634ed75d4790602401600060405180830381600087803b15801561040357600080fd5b505af1158015610417573d6000803e3d6000fd5b5050505050565b6104266107a8565b610430600061094a565b565b61043a6107a8565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b0382160161052e5747600081900361049d576040516316b4356760e31b815273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee60048201526024015b60405180910390fd5b604051600090339083908381818185875af1925050503d80600081146104df576040519150601f19603f3d011682016040523d82523d6000602084013e6104e4565b606091505b50509050806105295760405163ba1109b360e01b81523360048201526024810183905273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6044820152606401610494565b505050565b6040516370a0823160e01b815230600482015281906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610577573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059b9190611132565b9050806000036105c9576040516316b4356760e31b81526001600160a01b0384166004820152602401610494565b60405163a9059cbb60e01b8152336004820152602481018290526001600160a01b0383169063a9059cbb906044016020604051808303816000875af1158015610616573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063a9190611115565b50505050565b6106486107a8565b6001600160a01b0381166106ad5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610494565b6102e08161094a565b6000806106c96040860160208701611037565b6001600160a01b031614806106f55750306106ea6040860160208701611037565b6001600160a01b0316145b1561071357604051633649397d60e21b815260040160405180910390fd5b60ff610726610100860160e0870161115c565b60ff1603610747576040516304b4a0b760e51b815260040160405180910390fd5b600061075a610100860160e0870161115c565b60ff16036107745761076d84848461099a565b90506107a1565b34156107935760405163078d696560e31b815260040160405180910390fd5b61079e848484610aef565b90505b9392505050565b6000546001600160a01b031633146104305760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610494565b80158061087c5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015610856573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061087a9190611132565b155b6108e75760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610494565b6040516001600160a01b03831660248201526044810182905261052990849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152610d40565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000806109a73447611177565b90507f000000000000000000000000cafeac0ff5da0a2777d915531bfa6b29d282ee626001600160a01b031663f6579632348787876040518563ffffffff1660e01b81526004016109fa939291906112d5565b60206040518083038185885af1158015610a18573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610a3d9190611132565b91504781811115610ae6576000610a548383611177565b604051909150600090339083908381818185875af1925050503d8060008114610a99576040519150601f19603f3d011682016040523d82523d6000602084013e610a9e565b606091505b5050905080610ae35760405163ba1109b360e01b81523360048201526024810183905273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6044820152606401610494565b50505b50509392505050565b600080610afa610e12565b6001600160a01b031663eac8f5b8610b19610100880160e0890161115c565b6040516001600160e01b031960e084901b16815260ff9091166004820152602401606060405180830381865afa158015610b57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b7b9190611414565b516040516370a0823160e01b815230600482015290915081906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610bc8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bec9190611132565b9050610c076001600160a01b038316333060c08b0135610ea6565b604051637b2bcb1960e11b81526001600160a01b037f000000000000000000000000cafeac0ff5da0a2777d915531bfa6b29d282ee62169063f657963290610c57908a908a908a906004016112d5565b6020604051808303816000875af1158015610c76573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c9a9190611132565b6040516370a0823160e01b81523060048201529094506000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610ce4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d089190611132565b905081811115610ae3576000610d1e8383611177565b9050610d346001600160a01b0385163383610ede565b50505050509392505050565b6000610d95826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610f0e9092919063ffffffff16565b8051909150156105295780806020019051810190610db39190611115565b6105295760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610494565b6040516227050b60e31b815261503160f01b60048201526000907f00000000000000000000000001bfd82675dbcc7762c84019ca518e701c0cd07e6001600160a01b031690630138285890602401602060405180830381865afa158015610e7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ea19190611494565b905090565b6040516001600160a01b038085166024830152831660448201526064810182905261063a9085906323b872dd60e01b90608401610913565b6040516001600160a01b03831660248201526044810182905261052990849063a9059cbb60e01b90606401610913565b606061079e8484600085856001600160a01b0385163b610f705760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610494565b600080866001600160a01b03168587604051610f8c91906114d5565b60006040518083038185875af1925050503d8060008114610fc9576040519150601f19603f3d011682016040523d82523d6000602084013e610fce565b606091505b5091509150610fde828286610fe9565b979650505050505050565b60608315610ff85750816107a1565b8251156110085782518084602001fd5b8160405162461bcd60e51b815260040161049491906114f1565b6001600160a01b03811681146102e057600080fd5b60006020828403121561104957600080fd5b81356107a181611022565b803561105f81611022565b919050565b60008060006040848603121561107957600080fd5b833567ffffffffffffffff8082111561109157600080fd5b9085019061016082880312156110a657600080fd5b909350602085013590808211156110bc57600080fd5b818601915086601f8301126110d057600080fd5b8135818111156110df57600080fd5b8760206060830285010111156110f457600080fd5b6020830194508093505050509250925092565b80151581146102e057600080fd5b60006020828403121561112757600080fd5b81516107a181611107565b60006020828403121561114457600080fd5b5051919050565b803560ff8116811461105f57600080fd5b60006020828403121561116e57600080fd5b6107a18261114b565b8181038181111561119857634e487b7160e01b600052601160045260246000fd5b92915050565b803562ffffff8116811461105f57600080fd5b80356bffffffffffffffffffffffff8116811461105f57600080fd5b803563ffffffff8116811461105f57600080fd5b803561ffff8116811461105f57600080fd5b6000808335601e1984360301811261120a57600080fd5b830160208101925035905067ffffffffffffffff81111561122a57600080fd5b80360382131561123957600080fd5b9250929050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b818352600060208085019450826000805b868110156112c957823564ffffffffff8116808214611297578384fd5b895250828401356112a781611107565b151588850152604083810135908901526060978801979092019160010161127a565b50959695505050505050565b604081528335604082015260006112ee60208601611054565b6001600160a01b031660608301526113086040860161119e565b62ffffff16608083015261131e6060860161114b565b60ff1660a0830152611332608086016111b1565b6bffffffffffffffffffffffff1660c083015261135160a086016111cd565b63ffffffff811660e08401525061010060c08601358184015261137660e0870161114b565b6101206113878186018360ff169052565b6113928389016111e1565b925061014091506113a88286018461ffff169052565b6113b3818901611054565b9250506101606113cd818601846001600160a01b03169052565b6113d9828901896111f3565b9350915080610180860152506113f46101a085018383611240565b915050828103602084015261140a818587611269565b9695505050505050565b60006060828403121561142657600080fd5b6040516060810181811067ffffffffffffffff8211171561145757634e487b7160e01b600052604160045260246000fd5b604052825161146581611022565b8152602083015161147581611107565b6020820152604083015161148881611107565b60408201529392505050565b6000602082840312156114a657600080fd5b81516107a181611022565b60005b838110156114cc5781810151838201526020016114b4565b50506000910152565b600082516114e78184602087016114b1565b9190910192915050565b60208152600082518060208401526115108160408501602087016114b1565b601f01601f1916919091016040019291505056fea2646970667358221220593d74b7d681a037a54295bb24ae6ba8ce9f2820866ab4e44d4f5c41c32d193b64736f6c63430008120033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000cafeac0ff5da0a2777d915531bfa6b29d282ee62000000000000000000000000055cc48f7968fd8640ef140610dd4038e1b03926000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b00000000000000000000000001bfd82675dbcc7762c84019ca518e701c0cd07e00000000000000000000000046842a7d9372bb7dba08f0729393deda230a03b5

-----Decoded View---------------
Arg [0] : _cover (address): 0xcafeac0fF5dA0A2777d915531bfA6B29d282Ee62
Arg [1] : _memberRoles (address): 0x055CC48f7968FD8640EF140610dd4038e1b03926
Arg [2] : _nxmToken (address): 0xd7c49CEE7E9188cCa6AD8FF264C1DA2e69D4Cf3B
Arg [3] : _master (address): 0x01BFd82675DBCc7762C84019cA518e701C0cD07e
Arg [4] : _owner (address): 0x46842a7D9372bB7DBa08f0729393DEda230a03B5

-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 000000000000000000000000cafeac0ff5da0a2777d915531bfa6b29d282ee62
Arg [1] : 000000000000000000000000055cc48f7968fd8640ef140610dd4038e1b03926
Arg [2] : 000000000000000000000000d7c49cee7e9188cca6ad8ff264c1da2e69d4cf3b
Arg [3] : 00000000000000000000000001bfd82675dbcc7762c84019ca518e701c0cd07e
Arg [4] : 00000000000000000000000046842a7d9372bb7dba08f0729393deda230a03b5


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.