Sonic Blaze Testnet

Contract

0xDd3344EC59c6716CD159408E405cd64deB8EC12e

Overview

S Balance

Sonic Blaze LogoSonic Blaze LogoSonic Blaze Logo0 S

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

9 Internal Transactions found.

Latest 9 internal transactions

Parent Transaction Hash Block From To
234313502025-02-27 13:36:4011 days ago1740663400
0xDd3344EC...deB8EC12e
0 S
234313482025-02-27 13:36:3911 days ago1740663399
0xDd3344EC...deB8EC12e
0 S
234301082025-02-27 13:29:1011 days ago1740662950
0xDd3344EC...deB8EC12e
0 S
232074552025-02-26 14:55:1812 days ago1740581718
0xDd3344EC...deB8EC12e
0 S
232074522025-02-26 14:55:1712 days ago1740581717
0xDd3344EC...deB8EC12e
0 S
231995302025-02-26 14:07:4112 days ago1740578861
0xDd3344EC...deB8EC12e
0 S
229427222025-02-25 12:06:0913 days ago1740485169
0xDd3344EC...deB8EC12e
0 S
229427222025-02-25 12:06:0913 days ago1740485169
0xDd3344EC...deB8EC12e
0 S
229421252025-02-25 12:02:3913 days ago1740484959
0xDd3344EC...deB8EC12e
0 S
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xd4d06822...8Cc0526F6
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
StakingProducts

Compiler Version
v0.8.18+commit.87f61d96

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 21 : StakingProducts.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.18;

import "../../abstract/MasterAwareV2.sol";
import "../../abstract/Multicall.sol";
import "../../interfaces/ICover.sol";
import "../../interfaces/ICoverProducts.sol";
import "../../interfaces/IStakingProducts.sol";
import "../../interfaces/ITokenController.sol";
import "../../libraries/Math.sol";
import "../../libraries/SafeUintCast.sol";
import "../../libraries/StakingPoolLibrary.sol";

contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall {
  using SafeUintCast for uint;

  uint public constant SURGE_PRICE_RATIO = 2 ether;
  uint public constant SURGE_THRESHOLD_RATIO = 90_00; // 90.00%
  uint public constant SURGE_THRESHOLD_DENOMINATOR = 100_00; // 100.00%
  // base price bump
  // +0.2% for each 1% of capacity used, ie +20% for 100%
  uint public constant PRICE_BUMP_RATIO = 20_00; // 20%
  // bumped price smoothing
  // 0.5% per day
  uint public constant PRICE_CHANGE_PER_DAY = 200; // 2%
  uint public constant INITIAL_PRICE_DENOMINATOR = 100_00;
  uint public constant TARGET_PRICE_DENOMINATOR = 100_00;
  uint public constant MAX_TOTAL_WEIGHT = 20_00; // 20x

  // The 3 constants below are also used in the StakingPool contract
  uint public constant TRANCHE_DURATION = 91 days;
  uint public constant MAX_ACTIVE_TRANCHES = 8; // 7 whole quarters + 1 partial quarter
  uint public constant WEIGHT_DENOMINATOR = 100;

  // denominators for cover contract parameters
  uint public constant GLOBAL_CAPACITY_DENOMINATOR = 100_00;
  uint public constant CAPACITY_REDUCTION_DENOMINATOR = 100_00;

  uint public constant ONE_NXM = 1 ether;
  uint public constant ALLOCATION_UNITS_PER_NXM = 100;
  uint public constant NXM_PER_ALLOCATION_UNIT = ONE_NXM / ALLOCATION_UNITS_PER_NXM;

  // pool id => product id => Product
  mapping(uint => mapping(uint => StakedProduct)) private _products;
  // pool id => { totalEffectiveWeight, totalTargetWeight }
  mapping(uint => Weights) public weights;

  address public immutable coverContract;
  address public immutable stakingPoolFactory;

  constructor(address _coverContract, address _stakingPoolFactory) {
    coverContract = _coverContract;
    stakingPoolFactory = _stakingPoolFactory;
  }

  function getProductTargetWeight(uint poolId, uint productId) external view override returns (uint) {
    return uint(_products[poolId][productId].targetWeight);
  }

  function getTotalTargetWeight(uint poolId) external override view returns (uint) {
    return weights[poolId].totalTargetWeight;
  }

  function getTotalEffectiveWeight(uint poolId) external override view returns (uint) {
    return weights[poolId].totalEffectiveWeight;
  }

  function getProduct(uint poolId, uint productId) external override view returns (
    uint lastEffectiveWeight,
    uint targetWeight,
    uint targetPrice,
    uint bumpedPrice,
    uint bumpedPriceUpdateTime
  ) {
    StakedProduct memory product = _products[poolId][productId];
    return (
      product.lastEffectiveWeight,
      product.targetWeight,
      product.targetPrice,
      product.bumpedPrice,
      product.bumpedPriceUpdateTime
    );
  }

  function recalculateEffectiveWeights(uint poolId, uint[] calldata productIds) external {

    IStakingPool _stakingPool = stakingPool(poolId);

    uint[] memory capacityReductionRatios = coverProducts().getCapacityReductionRatios(productIds);
    uint globalCapacityRatio = cover().getGlobalCapacityRatio();

    uint _totalEffectiveWeight = weights[poolId].totalEffectiveWeight;

    for (uint i = 0; i < productIds.length; i++) {
      uint productId = productIds[i];
      StakedProduct memory _product = _products[poolId][productId];

      uint16 previousEffectiveWeight = _product.lastEffectiveWeight;
      _product.lastEffectiveWeight = _getEffectiveWeight(
        _stakingPool,
        productId,
        _product.targetWeight,
        globalCapacityRatio,
        capacityReductionRatios[i]
      );
      _totalEffectiveWeight = _totalEffectiveWeight - previousEffectiveWeight + _product.lastEffectiveWeight;
      _products[poolId][productId] = _product;
    }

    weights[poolId].totalEffectiveWeight = _totalEffectiveWeight.toUint32();
  }

  function recalculateEffectiveWeightsForAllProducts(uint poolId) external {

    ICoverProducts _coverProducts = coverProducts();
    IStakingPool _stakingPool = stakingPool(poolId);

    uint productsCount = _coverProducts.getProductCount();

    // initialize array for all possible products
    uint[] memory productIdsRaw = new uint[](productsCount);
    uint stakingPoolProductCount;

    // filter out products that are not in this pool
    for (uint i = 0; i < productsCount; i++) {
      if (_products[poolId][i].bumpedPriceUpdateTime == 0) {
        continue;
      }
      productIdsRaw[stakingPoolProductCount++] = i;
    }

    // use resized array
    uint[] memory productIds = new uint[](stakingPoolProductCount);

    for (uint i = 0; i < stakingPoolProductCount; i++) {
      productIds[i] = productIdsRaw[i];
    }

    uint globalCapacityRatio = cover().getGlobalCapacityRatio();
    uint[] memory capacityReductionRatios = _coverProducts.getCapacityReductionRatios(productIds);

    uint _totalEffectiveWeight;

    for (uint i = 0; i < stakingPoolProductCount; i++) {
      uint productId = productIds[i];
      StakedProduct memory _product = _products[poolId][productId];

      // Get current effectiveWeight
      _product.lastEffectiveWeight = _getEffectiveWeight(
        _stakingPool,
        productId,
        _product.targetWeight,
        globalCapacityRatio,
        capacityReductionRatios[i]
      );
      _totalEffectiveWeight += _product.lastEffectiveWeight;
      _products[poolId][productId] = _product;
    }

    weights[poolId].totalEffectiveWeight = _totalEffectiveWeight.toUint32();
  }

  function setProducts(uint poolId, StakedProductParam[] memory params) external {

    IStakingPool _stakingPool = stakingPool(poolId);

    if (msg.sender != _stakingPool.manager()) {
      revert OnlyManager();
    }

    (
      uint globalCapacityRatio,
      uint globalMinPriceRatio
    ) = ICover(coverContract).getGlobalCapacityAndPriceRatios();

    uint[] memory initialPriceRatios;
    uint[] memory capacityReductionRatios;

    {
      uint numProducts = params.length;
      uint[] memory productIds = new uint[](numProducts);

      for (uint i = 0; i < numProducts; i++) {
        productIds[i] = params[i].productId;
      }

      ICoverProducts _coverProducts = coverProducts();

      // reverts if poolId is not allowed for any of these products
      _coverProducts.requirePoolIsAllowed(productIds, poolId);

      initialPriceRatios = _coverProducts.getInitialPrices(productIds);
      capacityReductionRatios = _coverProducts.getCapacityReductionRatios(productIds);
    }

    Weights memory _weights = weights[poolId];
    bool targetWeightIncreased;

    for (uint i = 0; i < params.length; i++) {
      StakedProductParam memory _param = params[i];
      StakedProduct memory _product = _products[poolId][_param.productId];

      bool isNewProduct = _product.bumpedPriceUpdateTime == 0;

      // if this is a new product
      if (isNewProduct) {
        // initialize the bumpedPrice
        _product.bumpedPrice = initialPriceRatios[i].toUint96();
        _product.bumpedPriceUpdateTime = uint32(block.timestamp);
        // and make sure we set the price and the target weight
        if (!_param.setTargetPrice) {
          revert MustSetPriceForNewProducts();
        }
        if (!_param.setTargetWeight) {
          revert MustSetWeightForNewProducts();
        }
      }

      if (_param.setTargetPrice) {

        if (_param.targetPrice > TARGET_PRICE_DENOMINATOR) {
          revert TargetPriceTooHigh();
        }

        if (_param.targetPrice < globalMinPriceRatio) {
          revert TargetPriceBelowMin();
        }

        // if this is an existing product, when the target price is updated we need to calculate the
        // current base price using the old target price and update the bumped price to that value
        // uses the same logic as calculatePremium()
        if (!isNewProduct) {

          // apply price change per day towards previous target price
          uint newBumpedPrice = getBasePrice(
            _product.bumpedPrice,
            _product.bumpedPriceUpdateTime,
            _product.targetPrice,
            block.timestamp
          );

          // update product with new bumped price and bumped price update time
          _product.bumpedPrice = newBumpedPrice.toUint96();
          _product.bumpedPriceUpdateTime = block.timestamp.toUint32();
        }

        _product.targetPrice = _param.targetPrice;
      }

      // if setTargetWeight is set - effective weight must be recalculated
      if (_param.setTargetWeight && !_param.recalculateEffectiveWeight) {
        revert MustRecalculateEffectiveWeight();
      }

      // Must recalculate effectiveWeight to adjust targetWeight
      if (_param.recalculateEffectiveWeight) {

        if (_param.setTargetWeight) {
          if (_param.targetWeight > WEIGHT_DENOMINATOR) {
            revert TargetWeightTooHigh();
          }

          // totalEffectiveWeight cannot be above the max unless target  weight is not increased
          if (!targetWeightIncreased) {
            targetWeightIncreased = _param.targetWeight > _product.targetWeight;
          }
          _weights.totalTargetWeight = _weights.totalTargetWeight - _product.targetWeight + _param.targetWeight;
          _product.targetWeight = _param.targetWeight;
        }

        // subtract the previous effective weight
        _weights.totalEffectiveWeight -= _product.lastEffectiveWeight;

        _product.lastEffectiveWeight = _getEffectiveWeight(
          _stakingPool,
          _param.productId,
          _product.targetWeight,
          globalCapacityRatio,
          capacityReductionRatios[i]
        );

        // add the new effective weight
        _weights.totalEffectiveWeight += _product.lastEffectiveWeight;
      }

      // sstore
      _products[poolId][_param.productId] = _product;

      emit ProductUpdated(_param.productId, _param.targetWeight, _param.targetPrice);
    }

    if (_weights.totalTargetWeight > MAX_TOTAL_WEIGHT) {
      revert TotalTargetWeightExceeded();
    }

    if (targetWeightIncreased) {
      if (_weights.totalEffectiveWeight > MAX_TOTAL_WEIGHT) {
        revert TotalEffectiveWeightExceeded();
      }
    }

    weights[poolId] = _weights;
  }

  function getEffectiveWeight(
    uint poolId,
    uint productId,
    uint targetWeight,
    uint globalCapacityRatio,
    uint capacityReductionRatio
  ) public view returns (uint effectiveWeight) {

    IStakingPool _stakingPool = stakingPool(poolId);

    return _getEffectiveWeight(
      _stakingPool,
      productId,
      targetWeight,
      globalCapacityRatio,
      capacityReductionRatio
    );
  }

  function _getEffectiveWeight(
    IStakingPool _stakingPool,
    uint productId,
    uint targetWeight,
    uint globalCapacityRatio,
    uint capacityReductionRatio
  ) internal view returns (uint16 effectiveWeight) {

    uint activeStake = _stakingPool.getActiveStake();
    uint multiplier = globalCapacityRatio * (CAPACITY_REDUCTION_DENOMINATOR - capacityReductionRatio);
    uint denominator = GLOBAL_CAPACITY_DENOMINATOR * CAPACITY_REDUCTION_DENOMINATOR;
    uint totalCapacity = activeStake * multiplier / denominator / NXM_PER_ALLOCATION_UNIT;

    if (totalCapacity == 0) {
      return targetWeight.toUint16();
    }

    uint[] memory activeAllocations = _stakingPool.getActiveAllocations(productId);
    uint totalAllocation = Math.sum(activeAllocations);
    uint actualWeight = Math.min(totalAllocation * WEIGHT_DENOMINATOR / totalCapacity, type(uint16).max);

    return Math.max(targetWeight, actualWeight).toUint16();
  }

  /* pricing code */
  function getPremium(
    uint poolId,
    uint productId,
    uint period,
    uint coverAmount,
    uint initialCapacityUsed,
    uint totalCapacity,
    uint globalMinPrice,
    bool useFixedPrice,
    uint nxmPerAllocationUnit,
    uint allocationUnitsPerNXM
  ) public returns (uint premium) {

    if (msg.sender != StakingPoolLibrary.getAddress(stakingPoolFactory, poolId)) {
      revert OnlyStakingPool();
    }

    StakedProduct memory product = _products[poolId][productId];
    uint targetPrice = Math.max(product.targetPrice, globalMinPrice);

    if (useFixedPrice) {
      return calculateFixedPricePremium(coverAmount, period, targetPrice, nxmPerAllocationUnit, TARGET_PRICE_DENOMINATOR);
    }

    (premium, product) = calculatePremium(
      product,
      period,
      coverAmount,
      initialCapacityUsed,
      totalCapacity,
      targetPrice,
      block.timestamp,
      nxmPerAllocationUnit,
      allocationUnitsPerNXM,
      TARGET_PRICE_DENOMINATOR
    );

    // sstore
    _products[poolId][productId] = product;

    return premium;
  }

  function calculateFixedPricePremium(
    uint coverAmount,
    uint period,
    uint fixedPrice,
    uint nxmPerAllocationUnit,
    uint targetPriceDenominator
  ) public pure returns (uint) {

    uint premiumPerYear =
    coverAmount
    * nxmPerAllocationUnit
    * fixedPrice
    / targetPriceDenominator;

    return premiumPerYear * period / 365 days;
  }

  function getBasePrice(
    uint productBumpedPrice,
    uint productBumpedPriceUpdateTime,
    uint targetPrice,
    uint timestamp
  ) public pure returns (uint basePrice) {

    // use previously recorded bumped price and apply time based smoothing towards target price
    uint timeSinceLastUpdate = timestamp - productBumpedPriceUpdateTime;
    uint priceDrop = PRICE_CHANGE_PER_DAY * timeSinceLastUpdate / 1 days;

    // basePrice = max(targetPrice, bumpedPrice - priceDrop)
    // rewritten to avoid underflow
    return productBumpedPrice < targetPrice + priceDrop
      ? targetPrice
      : productBumpedPrice - priceDrop;
  }

  function calculatePremium(
    StakedProduct memory product,
    uint period,
    uint coverAmount,
    uint initialCapacityUsed,
    uint totalCapacity,
    uint targetPrice,
    uint currentBlockTimestamp,
    uint nxmPerAllocationUnit,
    uint allocationUnitsPerNxm,
    uint targetPriceDenominator
  ) public pure returns (uint premium, StakedProduct memory) {

    // calculate the bumped price by applying the price bump
    uint priceBump = PRICE_BUMP_RATIO * coverAmount / totalCapacity;

    // apply change in price-per-day towards the target price
    uint basePrice = getBasePrice(
       product.bumpedPrice,
       product.bumpedPriceUpdateTime,
       targetPrice,
       currentBlockTimestamp
     );

    // update product with new bumped price and timestamp
    product.bumpedPrice = (basePrice + priceBump).toUint96();
    product.bumpedPriceUpdateTime = uint32(currentBlockTimestamp);

    // use calculated base price and apply surge pricing if applicable
    uint premiumPerYear = calculatePremiumPerYear(
      basePrice,
      coverAmount,
      initialCapacityUsed,
      totalCapacity,
      nxmPerAllocationUnit,
      allocationUnitsPerNxm,
      targetPriceDenominator
    );

    // calculate the premium for the requested period
    return (premiumPerYear * period / 365 days, product);
  }

  function calculatePremiumPerYear(
    uint basePrice,
    uint coverAmount,
    uint initialCapacityUsed,
    uint totalCapacity,
    uint nxmPerAllocationUnit,
    uint allocationUnitsPerNxm,
    uint targetPriceDenominator
  ) public pure returns (uint) {
    // cover amount has 2 decimals (100 = 1 unit)
    // scale coverAmount to 18 decimals and apply price percentage
    uint basePremium = coverAmount * nxmPerAllocationUnit * basePrice / targetPriceDenominator;
    uint finalCapacityUsed = initialCapacityUsed + coverAmount;

    // surge price is applied for the capacity used above SURGE_THRESHOLD_RATIO.
    // the surge price starts at zero and increases linearly.
    // to simplify things, we're working with fractions/ratios instead of percentages,
    // ie 0 to 1 instead of 0% to 100%, 100% = 1 (a unit).
    //
    // surgeThreshold = SURGE_THRESHOLD_RATIO / SURGE_THRESHOLD_DENOMINATOR
    //                = 90_00 / 100_00 = 0.9
    uint surgeStartPoint = totalCapacity * SURGE_THRESHOLD_RATIO / SURGE_THRESHOLD_DENOMINATOR;

    // Capacity and surge pricing
    //
    //        i        f                         s
    //   ▓▓▓▓▓░░░░░░░░░                          ▒▒▒▒▒▒▒▒▒▒
    //
    //  i - initial capacity used
    //  f - final capacity used
    //  s - surge start point

    // if surge does not apply just return base premium
    // i < f <= s case
    if (finalCapacityUsed <= surgeStartPoint) {
      return basePremium;
    }

    // calculate the premium amount incurred due to surge pricing
    uint amountOnSurge = finalCapacityUsed - surgeStartPoint;
    uint surgePremium = calculateSurgePremium(amountOnSurge, totalCapacity, allocationUnitsPerNxm);

    // if the capacity start point is before the surge start point
    // the surge premium starts at zero, so we just return it
    // i <= s < f case
    if (initialCapacityUsed <= surgeStartPoint) {
      return basePremium + surgePremium;
    }

    // otherwise we need to subtract the part that was already used by other covers
    // s < i < f case
    uint amountOnSurgeSkipped = initialCapacityUsed - surgeStartPoint;
    uint surgePremiumSkipped = calculateSurgePremium(amountOnSurgeSkipped, totalCapacity, allocationUnitsPerNxm);

    return basePremium + surgePremium - surgePremiumSkipped;
  }

  // Calculates the premium for a given cover amount starting with the surge point
  function calculateSurgePremium(
    uint amountOnSurge,
    uint totalCapacity,
    uint allocationUnitsPerNxm
  ) public pure returns (uint) {

    // for every percent of capacity used, the surge price has a +2% increase per annum
    // meaning a +200% increase for 100%, ie x2 for a whole unit (100%) of capacity in ratio terms
    //
    // coverToCapacityRatio = amountOnSurge / totalCapacity
    // surgePriceStart = 0
    // surgePriceEnd = SURGE_PRICE_RATIO * coverToCapacityRatio
    //
    // surgePremium = amountOnSurge * surgePriceEnd / 2
    //              = amountOnSurge * SURGE_PRICE_RATIO * coverToCapacityRatio / 2
    //              = amountOnSurge * SURGE_PRICE_RATIO * amountOnSurge / totalCapacity / 2

    uint surgePremium = amountOnSurge * SURGE_PRICE_RATIO * amountOnSurge / totalCapacity / 2;

    // amountOnSurge has two decimals
    // dividing by ALLOCATION_UNITS_PER_NXM (=100) to normalize the result
    return surgePremium / allocationUnitsPerNxm;
  }

  /* ========== STAKING POOL CREATION ========== */

  function stakingPool(uint poolId) public view returns (IStakingPool) {
    return IStakingPool(
      StakingPoolLibrary.getAddress(address(stakingPoolFactory), poolId)
    );
  }

  function getStakingPoolCount() external view returns (uint) {
    return IStakingPoolFactory(stakingPoolFactory).stakingPoolCount();
  }

  function createStakingPool(
    bool isPrivatePool,
    uint initialPoolFee,
    uint maxPoolFee,
    ProductInitializationParams[] memory productInitParams,
    string calldata ipfsDescriptionHash
  ) external whenNotPaused onlyMember returns (uint /*poolId*/, address /*stakingPoolAddress*/) {

    ICoverProducts _coverProducts = coverProducts();

    ProductInitializationParams[] memory initializedProducts = _coverProducts.prepareStakingProductsParams(
      productInitParams
    );

    (uint poolId, address stakingPoolAddress) = ICompleteStakingPoolFactory(stakingPoolFactory).create(coverContract);

    IStakingPool(stakingPoolAddress).initialize(
      isPrivatePool,
      initialPoolFee,
      maxPoolFee,
      poolId,
      ipfsDescriptionHash
    );

    tokenController().assignStakingPoolManager(poolId, msg.sender);

    _setInitialProducts(poolId, initializedProducts);

    return (poolId, stakingPoolAddress);
  }

  function _setInitialProducts(uint poolId, ProductInitializationParams[] memory params) internal {

    uint globalMinPriceRatio = cover().getGlobalMinPriceRatio();
    uint totalTargetWeight;

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

      ProductInitializationParams memory param = params[i];

      if (params[i].targetPrice < globalMinPriceRatio) {
        revert TargetPriceBelowGlobalMinPriceRatio();
      }

      if (param.targetPrice > TARGET_PRICE_DENOMINATOR) {
        revert TargetPriceTooHigh();
      }

      if (param.weight > WEIGHT_DENOMINATOR) {
        revert TargetWeightTooHigh();
      }

      StakedProduct memory product;
      product.bumpedPrice = param.initialPrice;
      product.bumpedPriceUpdateTime = block.timestamp.toUint32();
      product.targetPrice = param.targetPrice;
      product.targetWeight = param.weight;
      product.lastEffectiveWeight = param.weight;

      // sstore
      _products[poolId][param.productId] = product;

      totalTargetWeight += param.weight;
    }

    if (totalTargetWeight > MAX_TOTAL_WEIGHT) {
      revert TotalTargetWeightExceeded();
    }

    weights[poolId] = Weights({
      totalTargetWeight: totalTargetWeight.toUint32(),
      totalEffectiveWeight: totalTargetWeight.toUint32()
    });
  }

  // future role transfers
  function changeStakingPoolFactoryOperator(address _operator) external onlyInternal {
    ICompleteStakingPoolFactory(stakingPoolFactory).changeOperator(_operator);
  }

  /* dependencies */

  function tokenController() internal view returns (ITokenController) {
    return ITokenController(internalContracts[uint(ID.TC)]);
  }

  function coverProducts() internal view returns (ICoverProducts) {
    return ICoverProducts(internalContracts[uint(ID.CP)]);
  }

  function cover() internal view returns (ICover) {
    return ICover(coverContract);
  }

  function changeDependentContractAddress() external {
    internalContracts[uint(ID.MR)] = master.getLatestAddress("MR");
    internalContracts[uint(ID.TC)] = master.getLatestAddress("TC");
    internalContracts[uint(ID.CP)] = master.getLatestAddress("CP");
  }

}

File 2 of 21 : 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 3 of 21 : 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 4 of 21 : MasterAwareV2.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.18;

import "../interfaces/ISAFURAMaster.sol";
import "../interfaces/IMasterAwareV2.sol";
import "../interfaces/IMemberRoles.sol";

abstract contract MasterAwareV2 is IMasterAwareV2 {

  ISAFURAMaster public master;

  mapping(uint => address payable) public internalContracts;

  modifier onlyMember {
    require(
      IMemberRoles(internalContracts[uint(ID.MR)]).checkRole(
        msg.sender,
        uint(IMemberRoles.Role.Member)
      ),
      "Caller is not a member"
    );
    _;
  }

  modifier onlyAdvisoryBoard {
    require(
      IMemberRoles(internalContracts[uint(ID.MR)]).checkRole(
        msg.sender,
        uint(IMemberRoles.Role.AdvisoryBoard)
      ),
      "Caller is not an advisory board member"
    );
    _;
  }

  modifier onlyInternal {
    require(master.isInternal(msg.sender), "Caller is not an internal contract");
    _;
  }

  modifier onlyMaster {
    if (address(master) != address(0)) {
      require(address(master) == msg.sender, "Not master");
    }
    _;
  }

  modifier onlyGovernance {
    require(
      master.checkIsAuthToGoverned(msg.sender),
      "Caller is not authorized to govern"
    );
    _;
  }

  modifier onlyEmergencyAdmin {
    require(
      msg.sender == master.emergencyAdmin(),
      "Caller is not emergency admin"
    );
    _;
  }

  modifier whenPaused {
    require(master.isPause(), "System is not paused");
    _;
  }

  modifier whenNotPaused {
    require(!master.isPause(), "System is paused");
    _;
  }

  function getInternalContractAddress(ID id) internal view returns (address payable) {
    return internalContracts[uint(id)];
  }

  function changeMasterAddress(address masterAddress) public onlyMaster {
    master = ISAFURAMaster(masterAddress);
  }

}

File 5 of 21 : Multicall.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.18;

abstract contract Multicall {

  error RevertedWithoutReason(uint index);

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

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

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

      if (!ok) {

        uint length = result.length;

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

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

      results[i] = result;
    }
  }
}

File 6 of 21 : ICompleteStakingPoolFactory.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "./IStakingPoolFactory.sol";

/**
 * @dev IStakingPoolFactory is missing the changeOperator() and operator() functions.
 * @dev Any change to the original interface will affect staking pool addresses
 * @dev This interface is created to add the missing functions so it can be used in other contracts.
 */
interface ICompleteStakingPoolFactory is IStakingPoolFactory {

  function operator() external view returns (address);

  function changeOperator(address newOperator) external;
}

File 7 of 21 : ICover.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

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

/* io structs */

enum ClaimMethod {
  IndividualClaims,
  YieldTokenIncidents
}

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

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

/* 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;
}

interface ICover {

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

  /* internal structs */

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

  /* storage structs */

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

  /* ========== 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 recalculateActiveCoverInAsset(uint coverAsset) external;

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

  function getGlobalCapacityRatio() external view returns (uint);

  function getGlobalRewardsRatio() external view returns (uint);

  function getGlobalMinPriceRatio() external pure returns (uint);

  function getGlobalCapacityAndPriceRatios() external view returns (
    uint _globalCapacityRatio,
    uint _globalMinPriceRatio
  );

  function GLOBAL_MIN_PRICE_RATIO() external view returns (uint);

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

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

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

  function changeStakingPoolFactoryOperator() external;

  function coverNFT() external returns (ICoverNFT);

  function stakingNFT() external returns (IStakingNFT);

  function stakingPoolFactory() external returns (ICompleteStakingPoolFactory);

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

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

  // Auth
  error OnlyOwnerOrApproved();

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

  // Products
  error ProductNotFound();
  error ProductDeprecated();
  error UnexpectedProductId();

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

  // Price & Commission
  error PriceExceedsMaxPremiumInAsset();
  error CommissionRateTooHigh();

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

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

File 8 of 21 : 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 changeNFTDescriptor(address newNFTDescriptor) 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 9 of 21 : ICoverProducts.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "./ICover.sol";

/* io structs */

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

/* storage structs */

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;
}

interface ICoverProducts {

  /* storage structs */

  struct Metadata {
    string ipfsHash;
    uint timestamp;
  }

  /* io structs */

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

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

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

  function getProductType(uint productTypeId) external view returns (ProductType memory);

  function getProductTypeName(uint productTypeId) external view returns (string memory);

  function getProductTypeCount() external view returns (uint);

  function getProductTypes() external view returns (ProductType[] memory);

  function getProduct(uint productId) external view returns (Product memory);

  function getProductName(uint productTypeId) external view returns (string memory);

  function getProductCount() external view returns (uint);

  function getProducts() external view returns (Product[] memory);

  // add grace period function?
  function getProductWithType(uint productId) external view returns (Product memory, ProductType memory);

  function getLatestProductMetadata(uint productId) external view returns (Metadata memory);

  function getLatestProductTypeMetadata(uint productTypeId) external view returns (Metadata memory);

  function getProductMetadata(uint productId) external view returns (Metadata[] memory);

  function getProductTypeMetadata(uint productTypeId) external view returns (Metadata[] memory);

  function getAllowedPools(uint productId) external view returns (uint[] memory _allowedPools);

  function getAllowedPoolsCount(uint productId) external view returns (uint);

  function isPoolAllowed(uint productId, uint poolId) external view returns (bool);

  function requirePoolIsAllowed(uint[] calldata productIds, uint poolId) external view;

  function getCapacityReductionRatios(uint[] calldata productIds) external view returns (uint[] memory);

  function getInitialPrices(uint[] calldata productIds) external view returns (uint[] memory);

  function prepareStakingProductsParams(
    ProductInitializationParams[] calldata params
  ) external returns (
    ProductInitializationParams[] memory validatedParams
  );

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

  function setProductTypes(ProductTypeParam[] calldata productTypes) external;

  function setProducts(ProductParam[] calldata params) external;

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

  event ProductSet(uint id);
  event ProductTypeSet(uint id);

  // Products and product types
  error ProductNotFound();
  error ProductTypeNotFound();
  error ProductDeprecated();
  error PoolNotAllowedForThisProduct(uint productId);
  error StakingPoolDoesNotExist();
  error MismatchedArrayLengths();
  error MetadataRequired();

  // Misc
  error UnsupportedCoverAssets();
  error InitialPriceRatioBelowGlobalMinPriceRatio();
  error InitialPriceRatioAbove100Percent();
  error CapacityReductionRatioAbove100Percent();

}

File 10 of 21 : IMasterAwareV2.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface IMasterAwareV2 {

  // TODO: if you update this enum, update lib/constants.js as well
  enum ID {
    TC, // TokenController.sol
    P1, // Pool.sol
    MR, // MemberRoles.sol
    MC, // MCR.sol
    CO, // Cover.sol
    SP, // StakingProducts.sol
    PS, // LegacyPooledStaking.sol
    GV, // Governance.sol
    GW, // LegacyGateway.sol - removed
    CL, // CoverMigrator.sol - removed
    AS, // Assessment.sol
    CI, // IndividualClaims.sol - Claims for Individuals
    CG, // YieldTokenIncidents.sol - Claims for Groups
    RA, // Ramm.sol
    ST,  // SafeTracker.sol
    CP  // CoverProducts.sol
  }

  function changeMasterAddress(address masterAddress) external;

  function changeDependentContractAddress() external;

  function internalContracts(uint) external view returns (address payable);
}

File 11 of 21 : IMemberRoles.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface IMemberRoles {

  enum Role {Unassigned, AdvisoryBoard, Member, Owner, Auditor}

  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 12 of 21 : ISAFURAMaster.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface ISAFURAMaster {

  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 13 of 21 : ISAFURAToken.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

interface ISAFURAToken {

  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 14 of 21 : 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 changeNFTDescriptor(address newNFTDescriptor) 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 15 of 21 : 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 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 OnlyStakingProductsContract();
  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 16 of 21 : 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);
}

File 17 of 21 : IStakingProducts.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "./ICoverProducts.sol";
import "./IStakingPool.sol";

interface IStakingProducts {

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

  struct Weights {
    uint32 totalEffectiveWeight;
    uint32 totalTargetWeight;
  }

  struct StakedProduct {
    uint16 lastEffectiveWeight;
    uint8 targetWeight;
    uint96 targetPrice;
    uint96 bumpedPrice;
    uint32 bumpedPriceUpdateTime;
  }

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

  function setProducts(uint poolId, StakedProductParam[] memory params) external;

  function getProductTargetWeight(uint poolId, uint productId) external view returns (uint);

  function getTotalTargetWeight(uint poolId) external view returns (uint);

  function getTotalEffectiveWeight(uint poolId) external view returns (uint);

  function getProduct(uint poolId, uint productId) external view returns (
    uint lastEffectiveWeight,
    uint targetWeight,
    uint targetPrice,
    uint bumpedPrice,
    uint bumpedPriceUpdateTime
  );

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

  function getPremium(
    uint poolId,
    uint productId,
    uint period,
    uint coverAmount,
    uint initialCapacityUsed,
    uint totalCapacity,
    uint globalMinPrice,
    bool useFixedPrice,
    uint nxmPerAllocationUnit,
    uint allocationUnitsPerNxm
  ) external returns (uint premium);

  function calculateFixedPricePremium(
    uint coverAmount,
    uint period,
    uint fixedPrice,
    uint nxmPerAllocationUnit,
    uint targetPriceDenominator
  ) external pure returns (uint);


  function calculatePremium(
    StakedProduct memory product,
    uint period,
    uint coverAmount,
    uint initialCapacityUsed,
    uint totalCapacity,
    uint targetPrice,
    uint currentBlockTimestamp,
    uint nxmPerAllocationUnit,
    uint allocationUnitsPerNxm,
    uint targetPriceDenominator
  ) external pure returns (uint premium, StakedProduct memory);

  function calculatePremiumPerYear(
    uint basePrice,
    uint coverAmount,
    uint initialCapacityUsed,
    uint totalCapacity,
    uint nxmPerAllocationUnit,
    uint allocationUnitsPerNxm,
    uint targetPriceDenominator
  ) external pure returns (uint);

  // Calculates the premium for a given cover amount starting with the surge point
  function calculateSurgePremium(
    uint amountOnSurge,
    uint totalCapacity,
    uint allocationUnitsPerNxm
  ) external pure returns (uint);

  /* ========== STAKING POOL CREATION ========== */

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

  function getStakingPoolCount() external view returns (uint);

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

  function changeStakingPoolFactoryOperator(address newOperator) external;

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

  event ProductUpdated(uint productId, uint8 targetWeight, uint96 targetPrice);

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

  // Auth
  error OnlyStakingPool();
  error OnlyCoverContract();
  error OnlyManager();

  // Products & weights
  error MustSetPriceForNewProducts();
  error MustSetWeightForNewProducts();
  error TargetPriceTooHigh();
  error TargetPriceBelowMin();
  error TargetWeightTooHigh();
  error MustRecalculateEffectiveWeight();
  error TotalTargetWeightExceeded();
  error TotalEffectiveWeightExceeded();

  // Staking Pool creation
  error ProductDoesntExistOrIsDeprecated();
  error InvalidProductType();
  error TargetPriceBelowGlobalMinPriceRatio();

}

File 18 of 21 : ITokenController.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "./ISAFURAToken.sol";

interface ITokenController {

  struct StakingPoolNXMBalances {
    uint128 rewards;
    uint128 deposits;
  }

  struct CoverInfo {
    uint16 claimCount;
    bool hasOpenClaim;
    bool hasAcceptedClaim;
    uint96 requestedPayoutAmount;
    // note: still 128 bits available here, can be used later
  }

  struct StakingPoolOwnershipOffer {
    address proposedManager;
    uint96 deadline;
  }

  function coverInfo(uint id) external view returns (
    uint16 claimCount,
    bool hasOpenClaim,
    bool hasAcceptedClaim,
    uint96 requestedPayoutAmount
  );

  function withdrawCoverNote(
    address _of,
    uint[] calldata _coverIds,
    uint[] calldata _indexes
  ) external;

  function changeOperator(address _newOperator) external;

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

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

  function addToWhitelist(address _member) external;

  function removeFromWhitelist(address _member) external;

  function mint(address _member, uint _amount) external;

  function lockForMemberVote(address _of, uint _days) external;

  function withdrawClaimAssessmentTokens(address[] calldata users) external;

  function getLockReasons(address _of) external view returns (bytes32[] memory reasons);

  function totalSupply() external view returns (uint);

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

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

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

  function token() external view returns (ISAFURAToken);

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

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

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

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

  function transferStakingPoolsOwnership(address from, address to) external;

  function assignStakingPoolManager(uint poolId, address manager) external;

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

  function acceptStakingPoolOwnershipOffer(uint poolId) external;

  function cancelStakingPoolOwnershipOffer(uint poolId) external;

  function mintStakingPoolNXMRewards(uint amount, uint poolId) external;

  function burnStakingPoolNXMRewards(uint amount, uint poolId) external;

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

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

  function burnStakedNXM(uint amount, uint poolId) external;

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

  function tokensLocked(address _of, bytes32 _reason) external view returns (uint256 amount);

  function getWithdrawableCoverNotes(
    address coverOwner
  ) external view returns (
    uint[] memory coverIds,
    bytes32[] memory lockReasons,
    uint withdrawableAmount
  );

  function getPendingRewards(address member) external view returns (uint);
}

File 19 of 21 : Math.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.18;

/**
 * @dev Simple library that defines min, max and babylonian sqrt functions
 */
library Math {

  function min(uint a, uint b) internal pure returns (uint) {
    return a < b ? a : b;
  }

  function max(uint a, uint b) internal pure returns (uint) {
    return a > b ? a : b;
  }

  function sum(uint[] memory items) internal pure returns (uint) {
    uint count = items.length;
    uint total;

    for (uint i = 0; i < count; i++) {
      total += items[i];
    }

    return total;
  }

  function divRound(uint a, uint b) internal pure returns (uint) {
    return (a + b / 2) / b;
  }

  function divCeil(uint a, uint b) internal pure returns (uint) {
    return (a + b - 1) / b;
  }

  function roundUp(uint a, uint b) internal pure returns (uint) {
    return divCeil(a, b) * b;
  }

  // babylonian method
  function sqrt(uint y) internal pure returns (uint) {

    if (y > 3) {
      uint z = y;
      uint x = y / 2 + 1;
      while (x < z) {
        z = x;
        x = (y / x + x) / 2;
      }
      return z;
    }

    if (y != 0) {
      return 1;
    }

    return 0;
  }

}

File 20 of 21 : SafeUintCast.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 21 of 21 : StakingPoolLibrary.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.18;

/**
 * @dev Simple library to derive the staking pool address from the pool id without external calls
 */
library StakingPoolLibrary {

  function getAddress(address factory, uint poolId) internal pure returns (address) {

    bytes32 hash = keccak256(
      abi.encodePacked(
        hex'ff',
        factory,
        poolId, // salt
        // init code hash of the MinimalBeaconProxy
        // updated using patch-staking-pool-library.js script
        hex'1eb804b66941a2e8465fa0951be9c8b855b7794ee05b0789ab22a02ee1298ebe' // init code hash
      )
    );

    // cast last 20 bytes of hash to address
    return address(uint160(uint(hash)));
  }

}

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

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_coverContract","type":"address"},{"internalType":"address","name":"_stakingPoolFactory","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidProductType","type":"error"},{"inputs":[],"name":"MustRecalculateEffectiveWeight","type":"error"},{"inputs":[],"name":"MustSetPriceForNewProducts","type":"error"},{"inputs":[],"name":"MustSetWeightForNewProducts","type":"error"},{"inputs":[],"name":"OnlyCoverContract","type":"error"},{"inputs":[],"name":"OnlyManager","type":"error"},{"inputs":[],"name":"OnlyStakingPool","type":"error"},{"inputs":[],"name":"ProductDoesntExistOrIsDeprecated","type":"error"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"RevertedWithoutReason","type":"error"},{"inputs":[],"name":"TargetPriceBelowGlobalMinPriceRatio","type":"error"},{"inputs":[],"name":"TargetPriceBelowMin","type":"error"},{"inputs":[],"name":"TargetPriceTooHigh","type":"error"},{"inputs":[],"name":"TargetWeightTooHigh","type":"error"},{"inputs":[],"name":"TotalEffectiveWeightExceeded","type":"error"},{"inputs":[],"name":"TotalTargetWeightExceeded","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"productId","type":"uint256"},{"indexed":false,"internalType":"uint8","name":"targetWeight","type":"uint8"},{"indexed":false,"internalType":"uint96","name":"targetPrice","type":"uint96"}],"name":"ProductUpdated","type":"event"},{"inputs":[],"name":"ALLOCATION_UNITS_PER_NXM","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CAPACITY_REDUCTION_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GLOBAL_CAPACITY_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"INITIAL_PRICE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_ACTIVE_TRANCHES","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_TOTAL_WEIGHT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NXM_PER_ALLOCATION_UNIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ONE_NXM","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRICE_BUMP_RATIO","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRICE_CHANGE_PER_DAY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SURGE_PRICE_RATIO","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SURGE_THRESHOLD_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SURGE_THRESHOLD_RATIO","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TARGET_PRICE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TRANCHE_DURATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WEIGHT_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"coverAmount","type":"uint256"},{"internalType":"uint256","name":"period","type":"uint256"},{"internalType":"uint256","name":"fixedPrice","type":"uint256"},{"internalType":"uint256","name":"nxmPerAllocationUnit","type":"uint256"},{"internalType":"uint256","name":"targetPriceDenominator","type":"uint256"}],"name":"calculateFixedPricePremium","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint16","name":"lastEffectiveWeight","type":"uint16"},{"internalType":"uint8","name":"targetWeight","type":"uint8"},{"internalType":"uint96","name":"targetPrice","type":"uint96"},{"internalType":"uint96","name":"bumpedPrice","type":"uint96"},{"internalType":"uint32","name":"bumpedPriceUpdateTime","type":"uint32"}],"internalType":"struct IStakingProducts.StakedProduct","name":"product","type":"tuple"},{"internalType":"uint256","name":"period","type":"uint256"},{"internalType":"uint256","name":"coverAmount","type":"uint256"},{"internalType":"uint256","name":"initialCapacityUsed","type":"uint256"},{"internalType":"uint256","name":"totalCapacity","type":"uint256"},{"internalType":"uint256","name":"targetPrice","type":"uint256"},{"internalType":"uint256","name":"currentBlockTimestamp","type":"uint256"},{"internalType":"uint256","name":"nxmPerAllocationUnit","type":"uint256"},{"internalType":"uint256","name":"allocationUnitsPerNxm","type":"uint256"},{"internalType":"uint256","name":"targetPriceDenominator","type":"uint256"}],"name":"calculatePremium","outputs":[{"internalType":"uint256","name":"premium","type":"uint256"},{"components":[{"internalType":"uint16","name":"lastEffectiveWeight","type":"uint16"},{"internalType":"uint8","name":"targetWeight","type":"uint8"},{"internalType":"uint96","name":"targetPrice","type":"uint96"},{"internalType":"uint96","name":"bumpedPrice","type":"uint96"},{"internalType":"uint32","name":"bumpedPriceUpdateTime","type":"uint32"}],"internalType":"struct IStakingProducts.StakedProduct","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"basePrice","type":"uint256"},{"internalType":"uint256","name":"coverAmount","type":"uint256"},{"internalType":"uint256","name":"initialCapacityUsed","type":"uint256"},{"internalType":"uint256","name":"totalCapacity","type":"uint256"},{"internalType":"uint256","name":"nxmPerAllocationUnit","type":"uint256"},{"internalType":"uint256","name":"allocationUnitsPerNxm","type":"uint256"},{"internalType":"uint256","name":"targetPriceDenominator","type":"uint256"}],"name":"calculatePremiumPerYear","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOnSurge","type":"uint256"},{"internalType":"uint256","name":"totalCapacity","type":"uint256"},{"internalType":"uint256","name":"allocationUnitsPerNxm","type":"uint256"}],"name":"calculateSurgePremium","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"changeDependentContractAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"masterAddress","type":"address"}],"name":"changeMasterAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"changeStakingPoolFactoryOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"coverContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"isPrivatePool","type":"bool"},{"internalType":"uint256","name":"initialPoolFee","type":"uint256"},{"internalType":"uint256","name":"maxPoolFee","type":"uint256"},{"components":[{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"uint8","name":"weight","type":"uint8"},{"internalType":"uint96","name":"initialPrice","type":"uint96"},{"internalType":"uint96","name":"targetPrice","type":"uint96"}],"internalType":"struct ProductInitializationParams[]","name":"productInitParams","type":"tuple[]"},{"internalType":"string","name":"ipfsDescriptionHash","type":"string"}],"name":"createStakingPool","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"productBumpedPrice","type":"uint256"},{"internalType":"uint256","name":"productBumpedPriceUpdateTime","type":"uint256"},{"internalType":"uint256","name":"targetPrice","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"getBasePrice","outputs":[{"internalType":"uint256","name":"basePrice","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"uint256","name":"targetWeight","type":"uint256"},{"internalType":"uint256","name":"globalCapacityRatio","type":"uint256"},{"internalType":"uint256","name":"capacityReductionRatio","type":"uint256"}],"name":"getEffectiveWeight","outputs":[{"internalType":"uint256","name":"effectiveWeight","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"uint256","name":"period","type":"uint256"},{"internalType":"uint256","name":"coverAmount","type":"uint256"},{"internalType":"uint256","name":"initialCapacityUsed","type":"uint256"},{"internalType":"uint256","name":"totalCapacity","type":"uint256"},{"internalType":"uint256","name":"globalMinPrice","type":"uint256"},{"internalType":"bool","name":"useFixedPrice","type":"bool"},{"internalType":"uint256","name":"nxmPerAllocationUnit","type":"uint256"},{"internalType":"uint256","name":"allocationUnitsPerNXM","type":"uint256"}],"name":"getPremium","outputs":[{"internalType":"uint256","name":"premium","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"}],"name":"getProduct","outputs":[{"internalType":"uint256","name":"lastEffectiveWeight","type":"uint256"},{"internalType":"uint256","name":"targetWeight","type":"uint256"},{"internalType":"uint256","name":"targetPrice","type":"uint256"},{"internalType":"uint256","name":"bumpedPrice","type":"uint256"},{"internalType":"uint256","name":"bumpedPriceUpdateTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"}],"name":"getProductTargetWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStakingPoolCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"getTotalEffectiveWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"getTotalTargetWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"internalContracts","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"master","outputs":[{"internalType":"contract ISAFURAMaster","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256[]","name":"productIds","type":"uint256[]"}],"name":"recalculateEffectiveWeights","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"recalculateEffectiveWeightsForAllProducts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"components":[{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"bool","name":"recalculateEffectiveWeight","type":"bool"},{"internalType":"bool","name":"setTargetWeight","type":"bool"},{"internalType":"uint8","name":"targetWeight","type":"uint8"},{"internalType":"bool","name":"setTargetPrice","type":"bool"},{"internalType":"uint96","name":"targetPrice","type":"uint96"}],"internalType":"struct IStakingProducts.StakedProductParam[]","name":"params","type":"tuple[]"}],"name":"setProducts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"poolId","type":"uint256"}],"name":"stakingPool","outputs":[{"internalType":"contract IStakingPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakingPoolFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"weights","outputs":[{"internalType":"uint32","name":"totalEffectiveWeight","type":"uint32"},{"internalType":"uint32","name":"totalTargetWeight","type":"uint32"}],"stateMutability":"view","type":"function"}]

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061025e5760003560e01c8063741cc2ea11610146578063b46ae21c116100c3578063d7a1748311610087578063d7a174831461050c578063d9c48a0314610661578063eb96236014610674578063ee97f7f31461069d578063f303d9be146106b0578063fbb8c9801461050c57600080fd5b8063b46ae21c14610577578063b5f163ff146105ab578063bf00d133146105fa578063c68b50e814610620578063d46655f41461064e57600080fd5b80639bf00f181161010a5780639bf00f1814610528578063a1b8adcb14610530578063a1f187091461050c578063a55a77a41461050c578063ac9650d81461055757600080fd5b8063741cc2ea146104ea5780637ca501a8146104f9578063809b18d5146102b957806383e250691461050c578063895cb0341461051557600080fd5b80632e0bbfc8116101df578063540b45ab116101a3578063540b45ab1461041957806356acd2c11461042c57806359bb18cd1461028957806365c00a57146104985780636d1b8e6b146104a7578063705d3860146104ba57600080fd5b80632e0bbfc8146103d05780634146f14e146103e357806341bd5db2146103eb57806347d30ab6146103fe5780634820c7651461040657600080fd5b8063200ebb5811610226578063200ebb58146102b957806321b0b0cb146102c157806323532c1b146102ec578063248a75b7146102f457806324f346ab1461031b57600080fd5b8063051a54fd1461026357806309a3bbe4146102895780630ea9c9841461029257806313d135ed1461029c5780631b955c02146102a6575b600080fd5b610276610271366004612d16565b6106b9565b6040519081526020015b60405180910390f35b6102766107d081565b61029a610711565b005b6102766277f88081565b61029a6102b4366004612d48565b610926565b610276606481565b6102d46102cf366004612d48565b610dd7565b6040516001600160a01b039091168152602001610280565b61027660c881565b6102d47f000000000000000000000000259f34a22bfa68afe2fc3cb860324bdf504be6be81565b6103a8610329366004612d61565b600091825260026020908152604080842092845291815291819020815160a081018352905461ffff811680835262010000820460ff16948301859052630100000082046001600160601b03908116948401859052600160781b83041660608401819052600160d81b90920463ffffffff16608090930183905294909190565b604080519586526020860194909452928401919091526060830152608082015260a001610280565b61029a6103de366004612e8d565b610e09565b610276611673565b6102766103f9366004612fa6565b611689565b610276600881565b610276610414366004612fe1565b6116d4565b61029a610427366004613075565b6118ea565b61043f61043a366004613092565b611a30565b60408051928352815161ffff1660208085019190915282015160ff16838201528101516001600160601b0390811660608085019190915282015116608080840191909152015163ffffffff1660a082015260c001610280565b610276670de0b6b3a764000081565b61029a6104b53660046131c8565b611b06565b6104cd6104c8366004613254565b611e10565b604080519283526001600160a01b03909116602083015201610280565b610276671bc16d674ec8000081565b61027661050736600461338f565b6121cb565b61027661271081565b6102766105233660046133db565b6122ac565b6102766122ef565b6102d47f000000000000000000000000df431fa3e1fd22f9f7d232bc45456c94d1ec043181565b61056a610565366004613407565b612378565b6040516102809190613448565b610276610585366004612d61565b600091825260026020908152604080842092845291905290205462010000900460ff1690565b6105dd6105b9366004612d48565b60036020526000908152604090205463ffffffff8082169164010000000090041682565b6040805163ffffffff938416815292909116602083015201610280565b610276610608366004612d48565b60009081526003602052604090205463ffffffff1690565b61027661062e366004612d48565b600090815260036020526040902054640100000000900463ffffffff1690565b61029a61065c366004613075565b6124bd565b61027661066f366004612fa6565b612537565b6102d4610682366004612d48565b6001602052600090815260409020546001600160a01b031681565b6000546102d4906001600160a01b031681565b61027661232881565b6000806106c685846134f0565b90506000620151806106d98360c8613503565b6106e3919061351a565b90506106ef818661353c565b8710610704576106ff81886134f0565b610706565b845b979650505050505050565b6000546040516227050b60e31b81526126a960f11b60048201526001600160a01b0390911690630138285890602401602060405180830381865afa15801561075d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610781919061354f565b6002600090815260016020527fd9d16d34ffb15ba3a3d852f0d403e2ce1d691fb54de27ac87cd2f993f3ec330f80546001600160a01b039384166001600160a01b0319909116179055546040516227050b60e31b815261544360f01b6004820152911690630138285890602401602060405180830381865afa15801561080b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061082f919061354f565b600080805260016020527fa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb4980546001600160a01b039384166001600160a01b0319909116179055546040516227050b60e31b815261043560f41b6004820152911690630138285890602401602060405180830381865afa1580156108b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108db919061354f565b600f60005260016020527f12bd632ff333b55931f9f8bda8b4ed27e86687f88c95871969d72474fb428c1480546001600160a01b0319166001600160a01b0392909216919091179055565b6000610930612561565b9050600061093d83610dd7565b90506000826001600160a01b0316634a348da96040518163ffffffff1660e01b8152600401602060405180830381865afa15801561097f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109a3919061356c565b90506000816001600160401b038111156109bf576109bf612d83565b6040519080825280602002602001820160405280156109e8578160200160208202803683370190505b5090506000805b83811015610a60576000878152600260209081526040808320848452909152902054600160d81b900463ffffffff1615610a4e57808383610a2f81613585565b945081518110610a4157610a4161359e565b6020026020010181815250505b80610a5881613585565b9150506109ef565b506000816001600160401b03811115610a7b57610a7b612d83565b604051908082528060200260200182016040528015610aa4578160200160208202803683370190505b50905060005b82811015610afb57838181518110610ac457610ac461359e565b6020026020010151828281518110610ade57610ade61359e565b602090810291909101015280610af381613585565b915050610aaa565b5060007f000000000000000000000000259f34a22bfa68afe2fc3cb860324bdf504be6be6001600160a01b03166378b4f6066040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b5c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b80919061356c565b90506000876001600160a01b031663fb9523a3846040518263ffffffff1660e01b8152600401610bb091906135ef565b600060405180830381865afa158015610bcd573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610bf59190810190613602565b90506000805b85811015610d9b576000858281518110610c1757610c1761359e565b60209081029190910181015160008e8152600283526040808220838352845290819020815160a081018352905461ffff8116825262010000810460ff16948201859052630100000081046001600160601b0390811693830193909352600160781b81049092166060820152600160d81b90910463ffffffff166080820152865191935091610cc4918d9185918a908a9089908110610cb757610cb761359e565b6020026020010151612588565b61ffff16808252610cd5908561353c565b60008e815260026020908152604080832095835294815290849020835181549285015195850151606086015160809096015163ffffffff16600160d81b0263ffffffff60d81b196001600160601b03978816600160781b02600160781b600160d81b031998909316630100000002979097166301000000600160d81b031960ff909916620100000262ffffff1990961661ffff90941693909317949094179690961617949094179290921691909117909155915080610d9381613585565b915050610bfb565b50610da581612732565b60009a8b5260036020526040909a20805463ffffffff191663ffffffff909b169a909a17909955505050505050505050565b6000610e037f000000000000000000000000df431fa3e1fd22f9f7d232bc45456c94d1ec04318361279b565b92915050565b6000610e1483610dd7565b9050806001600160a01b031663481c6a756040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e78919061354f565b6001600160a01b0316336001600160a01b031614610ea95760405163605919ad60e11b815260040160405180910390fd5b6000807f000000000000000000000000259f34a22bfa68afe2fc3cb860324bdf504be6be6001600160a01b031663ed2580056040518163ffffffff1660e01b81526004016040805180830381865afa158015610f09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f2d9190613687565b915091506060806000865190506000816001600160401b03811115610f5457610f54612d83565b604051908082528060200260200182016040528015610f7d578160200160208202803683370190505b50905060005b82811015610fd857888181518110610f9d57610f9d61359e565b602002602001015160000151828281518110610fbb57610fbb61359e565b602090810291909101015280610fd081613585565b915050610f83565b506000610fe3612561565b60405163d4179cbd60e01b81529091506001600160a01b0382169063d4179cbd906110149085908e906004016136ab565b60006040518083038186803b15801561102c57600080fd5b505afa158015611040573d6000803e3d6000fd5b50506040516305a34f7160e21b81526001600160a01b038416925063168d3dc491506110709085906004016135ef565b600060405180830381865afa15801561108d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526110b59190810190613602565b60405163fb9523a360e01b81529095506001600160a01b0382169063fb9523a3906110e49085906004016135ef565b600060405180830381865afa158015611101573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111299190810190613602565b60008b815260036020908152604080832081518083019092525463ffffffff8082168352640100000000909104169181019190915291955090935091508190505b88518110156115c65760008982815181106111875761118761359e565b60209081029190910181015160008d815260028352604080822083518352845290819020815160a081018352905461ffff8116825262010000810460ff1694820194909452630100000084046001600160601b0390811692820192909252600160781b84049091166060820152600160d81b90920463ffffffff1660808301819052909250158015611295576112358885815181106112285761122861359e565b602002602001015161281a565b6001600160601b0316606083015263ffffffff421660808084019190915283015161127357604051631b45045760e31b815260040160405180910390fd5b82604001516112955760405163a20b741160e01b815260040160405180910390fd5b826080015115611377576127108360a001516001600160601b031611156112cf57604051630d1dddf160e21b815260040160405180910390fd5b888360a001516001600160601b031610156112fd5760405163ed28495b60e01b815260040160405180910390fd5b8061136357600061133483606001516001600160601b0316846080015163ffffffff1685604001516001600160601b0316426106b9565b905061133f8161281a565b6001600160601b0316606084015261135642612732565b63ffffffff166080840152505b60a08301516001600160601b031660408301525b8260400151801561138a57508260200151155b156113a85760405163ef097d6560e01b815260040160405180910390fd5b8260200151156114b657826040015115611443576064836060015160ff1611156113e5576040516346975fdf60e11b815260040160405180910390fd5b846113fe57816020015160ff16836060015160ff161194505b826060015160ff16826020015160ff16876020015161141d91906136cd565b61142791906136f1565b63ffffffff16602080880191909152606084015160ff16908301525b816000015161ffff168660000181815161145d91906136cd565b91509063ffffffff16908163ffffffff16815250506114968b8460000151846020015160ff168d8b8981518110610cb757610cb761359e565b61ffff16808352865187906114ac9083906136f1565b63ffffffff169052505b60008d8152600260209081526040808320865184528252918290208451815486840151878601516060808a015160808b015161ffff90961662ffffff19909516949094176201000060ff94851602176301000000600160d81b03191663010000006001600160601b0393841602600160781b600160d81b03191617600160781b948316949094029390931763ffffffff60d81b1916600160d81b63ffffffff909516949094029390931790935587518189015160a08a015187519283529416948101949094529116928201929092527fa53c9996cef049b1d8795f6b98a35963de73d7096d884d7eb32fa2a64526b12e910160405180910390a150505080806115be90613585565b91505061116a565b506107d0826020015163ffffffff1611156115f457604051632de0ad0f60e11b815260040160405180910390fd5b8015611627576107d0826000015163ffffffff16111561162757604051632ce2fb1960e11b815260040160405180910390fd5b50600097885260036020908152604090982081518154999092015163ffffffff9081166401000000000267ffffffffffffffff19909a1692169190911797909717909655505050505050565b6116866064670de0b6b3a764000061351a565b81565b6000808285611698868a613503565b6116a29190613503565b6116ac919061351a565b90506301e133806116bd8783613503565b6116c7919061351a565b9150505b95945050505050565b60006117007f000000000000000000000000df431fa3e1fd22f9f7d232bc45456c94d1ec04318c61279b565b6001600160a01b0316336001600160a01b0316146117315760405163702580cd60e11b815260040160405180910390fd5b60008b81526002602090815260408083208d84528252808320815160a081018352905461ffff8116825262010000810460ff1693820193909352630100000083046001600160601b03908116928201839052600160781b8404166060820152600160d81b90920463ffffffff1660808301529091906117b0908861287e565b905085156117d0576117c78a8c8388612710611689565b925050506118dc565b6117e4828c8c8c8c86428c8c612710611a30565b809350819450505081600260008f815260200190815260200160002060008e815260200190815260200160002060008201518160000160006101000a81548161ffff021916908361ffff16021790555060208201518160000160026101000a81548160ff021916908360ff16021790555060408201518160000160036101000a8154816001600160601b0302191690836001600160601b03160217905550606082015181600001600f6101000a8154816001600160601b0302191690836001600160601b03160217905550608082015181600001601b6101000a81548163ffffffff021916908363ffffffff16021790555090505050505b9a9950505050505050505050565b6000546040516323c5b10760e21b81523360048201526001600160a01b0390911690638f16c41c90602401602060405180830381865afa158015611932573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611956919061370e565b6119b25760405162461bcd60e51b815260206004820152602260248201527f43616c6c6572206973206e6f7420616e20696e7465726e616c20636f6e74726160448201526118dd60f21b60648201526084015b60405180910390fd5b6040516306394c9b60e01b81526001600160a01b0382811660048301527f000000000000000000000000df431fa3e1fd22f9f7d232bc45456c94d1ec043116906306394c9b90602401600060405180830381600087803b158015611a1557600080fd5b505af1158015611a29573d6000803e3d6000fd5b5050505050565b6040805160a0810182526000808252602082018190529181018290526060810182905260808101829052600088611a698c6107d0613503565b611a73919061351a565b90506000611a9a8e606001516001600160601b03168f6080015163ffffffff168b8b6106b9565b9050611aae611aa9838361353c565b61281a565b6001600160601b031660608f015263ffffffff881660808f01526000611ad9828e8e8e8c8c8c6121cb565b90506301e13380611aea8f83613503565b611af4919061351a565b9f9d5050505050505050505050505050565b6000611b1184610dd7565b90506000611b1d612561565b6001600160a01b031663fb9523a385856040518363ffffffff1660e01b8152600401611b4a92919061372b565b600060405180830381865afa158015611b67573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611b8f9190810190613602565b905060007f000000000000000000000000259f34a22bfa68afe2fc3cb860324bdf504be6be6001600160a01b03166378b4f6066040518163ffffffff1660e01b8152600401602060405180830381865afa158015611bf1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c15919061356c565b60008781526003602052604081205491925063ffffffff909116905b85811015611dd7576000878783818110611c4d57611c4d61359e565b60008c8152600260209081526040808320938202959095013580835292815290849020845160a081018652905461ffff811680835260ff620100008304169383018490526001600160601b0363010000008304811697840197909752600160781b8204909616606083015263ffffffff600160d81b9091041660808201528951929550939250611cef918a9186918a908c908a908110610cb757610cb761359e565b61ffff90811680845290611d05908316876134f0565b611d0f919061353c565b60008c815260026020908152604080832096835295815290859020845181549286015196860151606087015160809097015163ffffffff16600160d81b0263ffffffff60d81b196001600160601b03988916600160781b02600160781b600160d81b031999909316630100000002989098166301000000600160d81b031960ff909a16620100000262ffffff1990961661ffff909416939093179490941797909716179590951793909316929092179092559250819050611dcf81613585565b915050611c31565b50611de181612732565b600097885260036020526040909720805463ffffffff191663ffffffff90981697909717909655505050505050565b6000805460408051600162f6c75960e01b03198152905183926001600160a01b03169163ff0938a79160048083019260209291908290030181865afa158015611e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e81919061370e565b15611ec15760405162461bcd60e51b815260206004820152601060248201526f14de5cdd195b481a5cc81c185d5cd95960821b60448201526064016119a9565b6002600081905260016020527fd9d16d34ffb15ba3a3d852f0d403e2ce1d691fb54de27ac87cd2f993f3ec330f5460405163505ef22f60e01b815233600482015260248101929092526001600160a01b03169063505ef22f90604401602060405180830381865afa158015611f3a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f5e919061370e565b611fa35760405162461bcd60e51b815260206004820152601660248201527521b0b63632b91034b9903737ba10309036b2b6b132b960511b60448201526064016119a9565b6000611fad612561565b90506000816001600160a01b03166394e5f369886040518263ffffffff1660e01b8152600401611fdd9190613764565b6000604051808303816000875af1158015611ffc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261202491908101906137d7565b6040516313db266360e31b81526001600160a01b037f000000000000000000000000259f34a22bfa68afe2fc3cb860324bdf504be6be8116600483015291925060009182917f000000000000000000000000df431fa3e1fd22f9f7d232bc45456c94d1ec043190911690639ed933189060240160408051808303816000875af11580156120b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120d991906138b1565b6040516314ec244360e31b815291935091506001600160a01b0382169063a761221890612114908f908f908f9088908f908f906004016138e1565b600060405180830381600087803b15801561212e57600080fd5b505af1158015612142573d6000803e3d6000fd5b5050505061214e612896565b6040516370504b2360e11b8152600481018490523360248201526001600160a01b03919091169063e0a0964690604401600060405180830381600087803b15801561219857600080fd5b505af11580156121ac573d6000803e3d6000fd5b505050506121ba82846128a1565b909b909a5098505050505050505050565b60008082896121da878b613503565b6121e49190613503565b6121ee919061351a565b905060006121fc898961353c565b9050600061271061220f6123288a613503565b612219919061351a565b905080821161222d57829350505050610706565b600061223982846134f0565b90506000612248828b8a6122ac565b9050828b116122675761225b818661353c565b95505050505050610706565b6000612273848d6134f0565b90506000612282828d8c6122ac565b90508061228f848961353c565b61229991906134f0565b9f9e505050505050505050505050505050565b600080600284866122c5671bc16d674ec8000082613503565b6122cf9190613503565b6122d9919061351a565b6122e3919061351a565b90506116cb838261351a565b60007f000000000000000000000000df431fa3e1fd22f9f7d232bc45456c94d1ec04316001600160a01b0316632dd96be96040518163ffffffff1660e01b8152600401602060405180830381865afa15801561234f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612373919061356c565b905090565b606081806001600160401b0381111561239357612393612d83565b6040519080825280602002602001820160405280156123c657816020015b60608152602001906001900390816123b15790505b50915060005b818110156124b557600080308787858181106123ea576123ea61359e565b90506020028101906123fc919061392e565b60405161240a929190613974565b600060405180830381855af49150503d8060008114612445576040519150601f19603f3d011682016040523d82523d6000602084013e61244a565b606091505b509150915081612482578051600081900361247b5760405163f1a8c42d60e01b8152600481018590526024016119a9565b8060208301fd5b808584815181106124955761249561359e565b6020026020010181905250505080806124ad90613585565b9150506123cc565b505092915050565b6000546001600160a01b031615612515576000546001600160a01b031633146125155760405162461bcd60e51b815260206004820152600a6024820152692737ba1036b0b9ba32b960b11b60448201526064016119a9565b600080546001600160a01b0319166001600160a01b0392909216919091179055565b60008061254387610dd7565b90506125528187878787612588565b61ffff16979650505050505050565b6000600181600f5b81526020810191909152604001600020546001600160a01b0316919050565b600080866001600160a01b03166317387b586040518163ffffffff1660e01b8152600401602060405180830381865afa1580156125c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125ed919061356c565b905060006125fd846127106134f0565b6126079086613503565b9050600061261761271080613503565b9050600061262e6064670de0b6b3a764000061351a565b826126398587613503565b612643919061351a565b61264d919061351a565b90508060000361266b5761266088612c53565b9450505050506116cb565b604051634618887f60e11b8152600481018a90526000906001600160a01b038c1690638c3110fe90602401600060405180830381865afa1580156126b3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526126db9190810190613602565b905060006126e882612cb6565b9050600061270d846126fb606485613503565b612705919061351a565b61ffff612d07565b905061272161271c8c8361287e565b612c53565b9d9c50505050505050505050505050565b600064010000000082106127975760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b60648201526084016119a9565b5090565b6040516001600160f81b031960208201526bffffffffffffffffffffffff19606084901b166021820152603581018290527f1eb804b66941a2e8465fa0951be9c8b855b7794ee05b0789ab22a02ee1298ebe6055820152600090819060750160408051808303601f190181529190528051602090910120949350505050565b6000600160601b82106127975760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203960448201526536206269747360d01b60648201526084016119a9565b600081831161288d578161288f565b825b9392505050565b600060018180612569565b60007f000000000000000000000000259f34a22bfa68afe2fc3cb860324bdf504be6be6001600160a01b0316631246da396040518163ffffffff1660e01b8152600401602060405180830381865afa158015612901573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612925919061356c565b90506000805b8351811015612bbb5760008482815181106129485761294861359e565b60200260200101519050838583815181106129655761296561359e565b6020026020010151606001516001600160601b0316101561299957604051637dbe145560e01b815260040160405180910390fd5b61271081606001516001600160601b031611156129c957604051630d1dddf160e21b815260040160405180910390fd5b6064816020015160ff1611156129f2576040516346975fdf60e11b815260040160405180910390fd5b6040805160a081018252600080825260208201819052818301819052606082018181526080830191909152918301516001600160601b0316909152612a3642612732565b816080019063ffffffff16908163ffffffff1681525050816060015181604001906001600160601b031690816001600160601b0316815250508160200151816020019060ff16908160ff1681525050816020015160ff16816000019061ffff16908161ffff1681525050806002600089815260200190815260200160002060008460000151815260200190815260200160002060008201518160000160006101000a81548161ffff021916908361ffff16021790555060208201518160000160026101000a81548160ff021916908360ff16021790555060408201518160000160036101000a8154816001600160601b0302191690836001600160601b03160217905550606082015181600001600f6101000a8154816001600160601b0302191690836001600160601b03160217905550608082015181600001601b6101000a81548163ffffffff021916908363ffffffff160217905550905050816020015160ff1684612ba4919061353c565b935050508080612bb390613585565b91505061292b565b506107d0811115612bdf57604051632de0ad0f60e11b815260040160405180910390fd5b6040518060400160405280612bf383612732565b63ffffffff168152602001612c0783612732565b63ffffffff908116909152600095865260036020908152604090962082518154939097015182166401000000000267ffffffffffffffff19909316969091169590951717909355505050565b60006201000082106127975760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b60648201526084016119a9565b805160009081805b82811015612cff57848181518110612cd857612cd861359e565b602002602001015182612ceb919061353c565b915080612cf781613585565b915050612cbe565b509392505050565b600081831061288d578161288f565b60008060008060808587031215612d2c57600080fd5b5050823594602084013594506040840135936060013592509050565b600060208284031215612d5a57600080fd5b5035919050565b60008060408385031215612d7457600080fd5b50508035926020909101359150565b634e487b7160e01b600052604160045260246000fd5b60405160c081016001600160401b0381118282101715612dbb57612dbb612d83565b60405290565b60405160a081016001600160401b0381118282101715612dbb57612dbb612d83565b604051608081016001600160401b0381118282101715612dbb57612dbb612d83565b604051601f8201601f191681016001600160401b0381118282101715612e2d57612e2d612d83565b604052919050565b60006001600160401b03821115612e4e57612e4e612d83565b5060051b60200190565b8015158114612e6657600080fd5b50565b60ff81168114612e6657600080fd5b6001600160601b0381168114612e6657600080fd5b6000806040808486031215612ea157600080fd5b833592506020808501356001600160401b03811115612ebf57600080fd5b8501601f81018713612ed057600080fd5b8035612ee3612ede82612e35565b612e05565b81815260c0918202830184019184820191908a841115612f0257600080fd5b938501935b83851015612f955780858c031215612f1f5760008081fd5b612f27612d99565b8535815286860135612f3881612e58565b8188015285880135612f4981612e58565b81890152606086810135612f5c81612e69565b90820152608086810135612f6f81612e58565b9082015260a086810135612f8281612e78565b9082015283529384019391850191612f07565b508096505050505050509250929050565b600080600080600060a08688031215612fbe57600080fd5b505083359560208501359550604085013594606081013594506080013592509050565b6000806000806000806000806000806101408b8d03121561300157600080fd5b8a35995060208b0135985060408b0135975060608b0135965060808b0135955060a08b0135945060c08b0135935060e08b013561303d81612e58565b809350506101008b013591506101208b013590509295989b9194979a5092959850565b6001600160a01b0381168114612e6657600080fd5b60006020828403121561308757600080fd5b813561288f81613060565b6000806000806000806000806000808a8c036101c08112156130b357600080fd5b60a08112156130c157600080fd5b506130ca612dc1565b8b3561ffff811681146130dc57600080fd5b815260208c01356130ec81612e69565b602082015260408c01356130ff81612e78565b604082015260608c013561311281612e78565b606082015260808c013563ffffffff8116811461312e57600080fd5b60808201529c60a08c01359c5060c08c01359b60e08101359b506101008101359a5061012081013599506101408101359850610160810135975061018081013596506101a00135945092505050565b60008083601f84011261318f57600080fd5b5081356001600160401b038111156131a657600080fd5b6020830191508360208260051b85010111156131c157600080fd5b9250929050565b6000806000604084860312156131dd57600080fd5b8335925060208401356001600160401b038111156131fa57600080fd5b6132068682870161317d565b9497909650939450505050565b60008083601f84011261322557600080fd5b5081356001600160401b0381111561323c57600080fd5b6020830191508360208285010111156131c157600080fd5b60008060008060008060a0878903121561326d57600080fd5b863561327881612e58565b955060208781013595506040880135945060608801356001600160401b03808211156132a357600080fd5b818a0191508a601f8301126132b757600080fd5b81356132c5612ede82612e35565b81815260079190911b8301840190848101908d8311156132e457600080fd5b938501935b82851015613357576080858f0312156133025760008081fd5b61330a612de3565b853581528686013561331b81612e69565b81880152604086013561332d81612e78565b6040820152606086013561334081612e78565b6060820152825260809490940193908501906132e9565b9750505060808a013592508083111561336f57600080fd5b505061337d89828a01613213565b979a9699509497509295939492505050565b600080600080600080600060e0888a0312156133aa57600080fd5b505085359760208701359750604087013596606081013596506080810135955060a0810135945060c0013592509050565b6000806000606084860312156133f057600080fd5b505081359360208301359350604090920135919050565b6000806020838503121561341a57600080fd5b82356001600160401b0381111561343057600080fd5b61343c8582860161317d565b90969095509350505050565b6000602080830181845280855180835260408601915060408160051b87010192508387016000805b838110156134cc57888603603f1901855282518051808852835b818110156134a5578281018a01518982018b0152890161348a565b508781018901849052601f01601f1916909601870195509386019391860191600101613470565b509398975050505050505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610e0357610e036134da565b8082028115828204841417610e0357610e036134da565b60008261353757634e487b7160e01b600052601260045260246000fd5b500490565b80820180821115610e0357610e036134da565b60006020828403121561356157600080fd5b815161288f81613060565b60006020828403121561357e57600080fd5b5051919050565b600060018201613597576135976134da565b5060010190565b634e487b7160e01b600052603260045260246000fd5b600081518084526020808501945080840160005b838110156135e4578151875295820195908201906001016135c8565b509495945050505050565b60208152600061288f60208301846135b4565b6000602080838503121561361557600080fd5b82516001600160401b0381111561362b57600080fd5b8301601f8101851361363c57600080fd5b805161364a612ede82612e35565b81815260059190911b8201830190838101908783111561366957600080fd5b928401925b828410156107065783518252928401929084019061366e565b6000806040838503121561369a57600080fd5b505080516020909101519092909150565b6040815260006136be60408301856135b4565b90508260208301529392505050565b63ffffffff8281168282160390808211156136ea576136ea6134da565b5092915050565b63ffffffff8181168382160190808211156136ea576136ea6134da565b60006020828403121561372057600080fd5b815161288f81612e58565b6020808252810182905260006001600160fb1b0383111561374b57600080fd5b8260051b80856040850137919091016040019392505050565b602080825282518282018190526000919060409081850190868401855b828110156137ca578151805185528681015160ff1687860152858101516001600160601b0390811687870152606091820151169085015260809093019290850190600101613781565b5091979650505050505050565b600060208083850312156137ea57600080fd5b82516001600160401b0381111561380057600080fd5b8301601f8101851361381157600080fd5b805161381f612ede82612e35565b81815260079190911b8201830190838101908783111561383e57600080fd5b928401925b82841015610706576080848903121561385c5760008081fd5b613864612de3565b845181528585015161387581612e69565b8187015260408581015161388881612e78565b9082015260608581015161389b81612e78565b9082015282526080939093019290840190613843565b600080604083850312156138c457600080fd5b8251915060208301516138d681613060565b809150509250929050565b861515815285602082015284604082015283606082015260a060808201528160a0820152818360c0830137600081830160c090810191909152601f909201601f1916010195945050505050565b6000808335601e1984360301811261394557600080fd5b8301803591506001600160401b0382111561395f57600080fd5b6020019150368190038213156131c157600080fd5b818382376000910190815291905056fea2646970667358221220d2c3110f6293e9a3d78b0860056c6f8260da23399943f0eff16b1a634c5365ce64736f6c63430008120033

Block Transaction 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
[ 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.