Contract 0xCe7CB20Ef71341B4654eE0Bbcbc92A33d5f1c6Af

Txn Hash Method
Block
From
To
Value [Txn Fee]
0xcc8be0577d2df28f9078f3e08eae01f7224131e0aaa7e8ffa5e2cc7ff6dc7eea0x61497261163283452022-06-21 14:02:0497 days 50 mins agoYield Yak: Deployer IN  Create: StakeUtils0 AVAX0.13573200333
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.

Contract Source Code Verified (Exact Match)

Contract Name:
StakeUtils

Compiler Version
v0.8.7+commit.e28d00a7

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 14 : StakeUtilsLib.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.8.7;

import "@openzeppelin/contracts/proxy/Clones.sol";
import "../../interfaces/ISwap.sol";
import "../../interfaces/IgAVAX.sol";
import "../../WithdrawalPool/LPToken.sol";
import "./DataStoreLib.sol";

/**
 * @title StakeUtils library
 * @notice Exclusively contains functions related to Avax Liquid Staking designed by Geode Finance
 * @notice biggest part of the functionality is related to Withdrawal Pools
 * which relies on continuous buybacks for price peg with DEBT/SURPLUS calculations
 * @dev Contracts relying on this library must initialize StakeUtils.StakePool
 * @dev ALL "fee" variables are limited by FEE_DENOMINATOR = 100%
 * Note *suggested* refer to GeodeUtils before reviewing
 * Note refer to DataStoreUtils before reviewing
 * Note beware of the staking pool and operator implementations:
 * Operatores have properties like accumulatedFee, fee(as a percentage), maintainer.
 * Every staking pool(aka planet) is also an operator by design.
 * Planets(type 5) inherit operators (type 4), with additional properties like staking pools -relates to
 * params: pBalance, surplus, unclaimedFees-, withdrawal pool - relates to debt - and liquid asset(gAvax).
 */
library StakeUtils {
  using DataStoreUtils for DataStoreUtils.DataStore;

  event MaintainerFeeUpdated(uint256 id, uint256 fee);
  event MaxMaintainerFeeUpdated(uint256 newMaxFee);
  event PriceChanged(uint256 id, uint256 pricePerShare);
  event OracleUpdate(
    uint256 id,
    uint256 price,
    uint256 newPBalance,
    uint256 distributedFeeTotal,
    uint256 updateTimeStamp
  );
  event OperatorActivated(uint256 id, uint256 activeOperator);
  event OperatorDeactivated(uint256 id, uint256 deactiveOperator);
  event debtPaid(uint256 id, uint256 operatorId, uint256 paidDebt);
  event SurplusClaimed(uint256 id, uint256 newSurplus);
  event FeeClaimed(uint256 id, uint256 claimerId, uint256 newSurplus);
  event PausedPool(uint256 id);
  event UnpausedPool(uint256 id);

  /**
   * @notice StakePool includes the parameters related to Staking Pool Contracts.
   * @notice A staking pool works with a *bound* Withdrawal Pool to create best pricing
   * for the staking derivative. Withdrawal Pools uses StableSwap algorithm.
   * @param gAVAX ERC1155 contract that keeps the totalSupply, pricepershare and balances of all StakingPools by ID
   * @dev  gAVAX should not be changed ever!
   * @param DEFAULT_SWAP_POOL STABLESWAP pool that will be cloned to be used as Withdrawal Pool of given ID
   * @param DEFAULT_LP_TOKEN LP token implementation that will be cloned to be used for Withdrawal Pool of given ID
   * @param ORACLE https://github.com/Geodefi/Telescope
   * @param DEFAULT_A Withdrawal Pool parameter
   * @param DEFAULT_FEE Withdrawal Pool parameter
   * @param DEFAULT_ADMIN_FEE Withdrawal Pool parameter
   * @param FEE_DENOMINATOR represents 100% ALSO Withdrawal Pool parameter
   * @param MAX_MAINTAINER_FEE : limits operator.fee and planet.fee, set by GOVERNANCE
   * @dev changing any of address parameters (gAVAX, ORACLE, DEFAULT_SWAP_POOL, DEFAULT_LP_TOKEN) MUST require a contract upgrade to ensure security
   **/
  struct StakePool {
    address gAVAX;
    address DEFAULT_SWAP_POOL;
    address DEFAULT_LP_TOKEN;
    address ORACLE;
    uint256 DEFAULT_A;
    uint256 DEFAULT_FEE;
    uint256 DEFAULT_ADMIN_FEE;
    uint256 FEE_DENOMINATOR;
    uint256 PERIOD_PRICE_INCREASE_LIMIT;
    uint256 MAX_MAINTAINER_FEE;
  }

  /**
   * @notice gAVAX lacks *decimals*,
   * @dev gAVAX_DENOMINATOR makes sure that we are taking care of decimals on calculations related to gAVAX
   */
  uint256 constant gAVAX_DENOMINATOR = 1e18;

  /// @notice Oracle is active for the first 30 min for a day
  uint256 constant ORACLE_PERIOD = 1 days;
  uint256 constant ORACLE_ACTIVE_PERIOD = 30 minutes;
  uint256 constant DEACTIVATION_PERIOD = 15 days;
  uint256 constant IGNORABLE_DEBT = 1 ether;

  /**
   * @notice whenever an operator is activated for a staking pool, it sets an activationExpiration date, which
   * means the op pay debt by burning gAvax tokens and collect fee from their validators.
   * While this implementation allows any two different ids to cooperate, with multiple interactions at any given time,
   * there can only be "1" activeOperator who can also claimSurplus to create new validators.
   */
  modifier beforeActivationExpiration(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _poolId,
    uint256 _claimerId
  ) {
    require(
      _DATASTORE.readUintForId(
        _poolId,
        bytes32(keccak256(abi.encodePacked(_claimerId, "activationExpiration")))
      ) > block.timestamp,
      "StakeUtils: operatorId activationExpiration has past"
    );
    _;
  }

  modifier onlyMaintainer(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id
  ) {
    require(
      _DATASTORE.readAddressForId(_id, "maintainer") == msg.sender,
      "StakeUtils: sender not maintainer"
    );
    _;
  }

  function _clone(address target) public returns (address) {
    return Clones.clone(target);
  }

  function getgAVAX(StakePool storage self) public view returns (IgAVAX) {
    return IgAVAX(self.gAVAX);
  }

  /**
   * @notice                      ** Maintainer specific functions **
   *
   * @note "Maintainer" is a shared logic like "fee" by both operator and pools.
   * Maintainers have permissiones to maintain the given id like setting a new fee or interface as
   * well as paying debt etc. for operators.
   * @dev maintainer is set by CONTROLLER of given id
   */

  /// @notice even if MAX_MAINTAINER_FEE is decreased later, it returns limited maximum
  function getMaintainerFee(
    StakePool storage self,
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id
  ) public view returns (uint256) {
    return
      _DATASTORE.readUintForId(_id, "fee") > self.MAX_MAINTAINER_FEE
        ? self.MAX_MAINTAINER_FEE
        : _DATASTORE.readUintForId(_id, "fee");
  }

  function setMaintainerFee(
    StakePool storage self,
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id,
    uint256 _newFee
  ) external onlyMaintainer(_DATASTORE, _id) {
    require(
      _newFee <= self.MAX_MAINTAINER_FEE,
      "StakeUtils: MAX_MAINTAINER_FEE ERROR"
    );
    _DATASTORE.writeUintForId(_id, "fee", _newFee);
    emit MaintainerFeeUpdated(_id, _newFee);
  }

  function setMaxMaintainerFee(StakePool storage self, uint256 _newMaxFee)
    external
  {
    require(
      _newMaxFee <= self.FEE_DENOMINATOR,
      "StakeUtils: fee more than 100%"
    );
    self.MAX_MAINTAINER_FEE = _newMaxFee;
    emit MaxMaintainerFeeUpdated(_newMaxFee);
  }

  function changeMaintainer(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id,
    address _newMaintainer
  ) external {
    require(
      _DATASTORE.readAddressForId(_id, "CONTROLLER") == msg.sender,
      "StakeUtils: not CONTROLLER of given id"
    );
    require(
      _newMaintainer != address(0),
      "StakeUtils: maintainer can not be zero"
    );

    _DATASTORE.writeAddressForId(_id, "maintainer", _newMaintainer);
  }

  /**
   * @notice                      ** Staking Pool specific functions **
   */

  /// @notice mints gAVAX tokens with given ID and amount.
  /// @dev shouldn't be accesible publicly
  function _mint(
    address _gAVAX,
    address _to,
    uint256 _id,
    uint256 _amount
  ) internal {
    require(_id > 0, "StakeUtils: _mint id should be > 0");
    IgAVAX(_gAVAX).mint(_to, _id, _amount, "");
  }

  /**
   * @notice conducts a buyback using the given withdrawal pool,
   * @param to address to send bought gAVAX(id). burns the tokens if to=address(0), transfers if not
   * @param poolId id of the gAVAX that will be bought
   * @param sellAvax AVAX amount to sell
   * @param minToBuy TX is expected to revert by Swap.sol if not meet
   * @param deadline TX is expected to revert by Swap.sol if deadline has past
   * @dev this function assumes that pool is deployed by deployWithdrawalPool
   * as index 0 is avax and index 1 is Gavax
   */
  function _buyback(
    StakePool storage self,
    DataStoreUtils.DataStore storage _DATASTORE,
    address to,
    uint256 poolId,
    uint256 sellAvax,
    uint256 minToBuy,
    uint256 deadline
  ) internal returns (uint256 outAmount) {
    // SWAP in WP
    outAmount = withdrawalPoolById(_DATASTORE, poolId).swap{ value: sellAvax }(
      0,
      1,
      sellAvax,
      minToBuy,
      deadline
    );
    if (to == address(0)) {
      // burn
      getgAVAX(self).burn(address(this), poolId, outAmount);
    } else {
      // send back to user
      getgAVAX(self).safeTransferFrom(address(this), to, poolId, outAmount, "");
    }
  }

  /**
   * @notice                      ** ORACLE specific functions **
   */

  /**
   * @notice sets pricePerShare parameter of gAVAX(id)
   * @dev only ORACLE should be able to reach this after sanity checks on new price
   */
  function _setPricePerShare(
    StakePool storage self,
    uint256 pricePerShare_,
    uint256 _id
  ) internal {
    require(_id > 0, "StakeUtils: id should be > 0");
    getgAVAX(self).setPricePerShare(pricePerShare_, _id);
    emit PriceChanged(_id, pricePerShare_);
  }

  /**
   * @notice Oracle is only allowed for a period every day & pool operations are stopped then
   * @return false if the last oracle update happened already (within the current daily period)
   */
  function _isOracleActive(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _poolId
  ) internal view returns (bool) {
    return
      (block.timestamp % ORACLE_PERIOD <= ORACLE_ACTIVE_PERIOD) &&
      (_DATASTORE.readUintForId(_poolId, "oracleUpdateTimeStamp") <
        block.timestamp - ORACLE_ACTIVE_PERIOD);
  }

  /**
   * @notice oraclePrice is a reliable source for any contract operation
   * @dev also the *mint price* when there is a no debt
   */
  function oraclePrice(StakePool storage self, uint256 _id)
    public
    view
    returns (uint256 _oraclePrice)
  {
    _oraclePrice = getgAVAX(self).pricePerShare(_id);
  }

  /**
   * @notice in order to prevent attacks from malicious Oracle there are boundaries to price & fee updates.
   * @dev checks:
   * 1. Price should be increased & it should not be increased more than PERIOD_PRICE_INCREASE_LIMIT
   *  with the factor of how many days since oracleUpdateTimeStamp has past.
   *  To encourage report oracle each day, price increase limit is not calculated by considering compound effect
   *  for multiple days.
   */
  function _sanityCheck(
    StakePool storage self,
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id,
    uint256 _newPrice
  ) internal view {
    // need to put the lastPriceUpdate to DATASTORE to check if price is updated already for that day
    uint256 periodsSinceUpdate = (block.timestamp +
      ORACLE_ACTIVE_PERIOD -
      _DATASTORE.readUintForId(_id, "oracleUpdateTimeStamp")) / ORACLE_PERIOD;
    uint256 curPrice = oraclePrice(self, _id);
    uint256 maxPrice = curPrice +
      ((curPrice * self.PERIOD_PRICE_INCREASE_LIMIT * periodsSinceUpdate) /
        self.FEE_DENOMINATOR);

    require(
      _newPrice <= maxPrice && _newPrice >= curPrice,
      "StakeUtils: price did NOT met"
    );
  }

  /**
   * @notice distribute fees to given operator Ids, by related to their fees.
   * Finally, distribute the fee of maintainer of the pool from total amounts.
   *
   * @dev fees can be higher than current MAX, if MAX is changed afterwards, we check that condition.
   */
  function _distributeFees(
    StakePool storage self,
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _poolId,
    uint256[] calldata _opIds,
    uint256[] calldata _pBalanceIncreases
  ) internal returns (uint256 totalPBalanceIncrease, uint256 totalFees) {
    require(
      _opIds.length == _pBalanceIncreases.length,
      "StakeUtils: Array lengths doesn't match"
    );

    for (uint256 i = 0; i < _opIds.length; i++) {
      // do not double spend if pool maintainer is also maintaining the validators
      if (_opIds[i] != _poolId) {
        // check IdCooperation[keccak256(abi.encodePacked(_id, operator))]
        require(
          _DATASTORE.readUintForId(
            _poolId,
            bytes32(
              keccak256(abi.encodePacked(_opIds[i], "activationExpiration"))
            )
          ) > block.timestamp - ORACLE_PERIOD,
          "StakeUtils: _opId activationExpiration has past"
        );
        uint256 opFee = getMaintainerFee(self, _DATASTORE, _opIds[i]);
        (uint256 _fee, bytes32 _key) = accumulatedFee(
          _DATASTORE,
          _poolId,
          _opIds[i]
        );
        uint256 gainedOpFee = (opFee * _pBalanceIncreases[i]) /
          self.FEE_DENOMINATOR;
        _DATASTORE.writeUintForId(_poolId, _key, _fee + gainedOpFee);
        totalFees += gainedOpFee;
      }
      totalPBalanceIncrease += _pBalanceIncreases[i];
    }

    // op_fee * _pBalanceIncrease[i] to calculate respective fee from the gained increase
    uint256 poolFee = getMaintainerFee(self, _DATASTORE, _poolId);
    uint256 gainedPoolFee = (poolFee * totalPBalanceIncrease) /
      self.FEE_DENOMINATOR;

    (uint256 fee, bytes32 key) = accumulatedFee(_DATASTORE, _poolId, _poolId);
    totalFees += gainedPoolFee;
    _DATASTORE.writeUintForId(_poolId, key, fee + gainedPoolFee);
  }

  /**
   * @notice only Oracle can report a new price. However price is not purely calculated by it.
   * the balance on P subchain is estimated by it, including the unrealized staking rewards.
   * Oracle has a pessimistic approach to make sure price will not decrease by a lot even in the case of loss of funds.

   * @param _reportedTimeStamp ensures prepeared report is prepeared within last activation period, prevent previous reports to be accepted. 
   * @param _opIds all ids of all operators who still collect fees.
   * @param _pBalanceIncreases the amount of avax that has been gained by the operator as POS rewards, respective to _opIds
   * @dev simply the new price is found by (pBALANCE + surplus - fees) / totalSupply)
   * @return price : new price after sanitychecks, might be useful if onchain oracle in the future
   */
  function reportOracle(
    StakePool storage self,
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _reportedTimeStamp,
    uint256 _poolId,
    uint256[] calldata _opIds,
    uint256[] calldata _pBalanceIncreases
  ) external returns (uint256 price) {
    require(msg.sender == self.ORACLE, "StakeUtils: msg.sender NOT oracle");
    require(
      _isOracleActive(_DATASTORE, _poolId),
      "StakeUtils: Oracle is NOT active"
    );
    require(
      _reportedTimeStamp >= block.timestamp - ORACLE_ACTIVE_PERIOD,
      "StakeUtils: Reported timestamp is NOT valid"
    );

    // distribute fees
    (uint256 totalPBalanceIncrease, uint256 totalFees) = _distributeFees(
      self,
      _DATASTORE,
      _poolId,
      _opIds,
      _pBalanceIncreases
    );

    uint256 newPBalance = _DATASTORE.readUintForId(_poolId, "pBalance") +
      totalPBalanceIncrease;
    _DATASTORE.writeUintForId(_poolId, "pBalance", newPBalance);

    uint256 unclaimed = _DATASTORE.readUintForId(_poolId, "unclaimedFees") +
      totalFees;
    _DATASTORE.writeUintForId(_poolId, "unclaimedFees", unclaimed);

    // deduct unclaimed fees from surplus
    price =
      ((newPBalance +
        _DATASTORE.readUintForId(_poolId, "surplus") -
        unclaimed) * gAVAX_DENOMINATOR) /
      (getgAVAX(self).totalSupply(_poolId));
    _sanityCheck(self, _DATASTORE, _poolId, price);
    _setPricePerShare(self, price, _poolId);

    _DATASTORE.writeUintForId(
      _poolId,
      "oracleUpdateTimeStamp",
      block.timestamp
    );
    emit OracleUpdate(
      _poolId,
      price,
      newPBalance,
      totalFees,
      _reportedTimeStamp
    );
  }

  /**
   * @notice                      ** DEBT/SURPLUS/FEE specific functions **
   */

  /**
   * @notice When a pool maintainer wants another operator's maintainer to be able to start claiming surplus and
   * creating validators, it activates the validator.
   * @notice Changes activeOperator of the given ID; old activeOperator can NOT claim surplus anymore
   * @dev However it can still continue holding its old balance until activationExpiration, and gain fees
   * @dev activationExpiration timestamp until new activeoperator continues getting fees from id's staking pool
   */
  function activateOperator(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id,
    uint256 _activeId
  ) external onlyMaintainer(_DATASTORE, _id) returns (bool) {
    _DATASTORE.writeUintForId(_id, "activeOperator", _activeId);
    _DATASTORE.writeUintForId(
      _id,
      bytes32(keccak256(abi.encodePacked(_activeId, "activationExpiration"))),
      type(uint256).max
    );
    emit OperatorActivated(_id, _activeId);
    return true;
  }

  /**
   * @notice deactivates an old operator for the given staking pool
   * @dev when activationExpiration is up, operator will NOT be able generate fees from pool,
   * it is expected for them to return the assets as surplus with payDebt function
   * @dev _deactivateAfter seconds until activation expires,
   */
  function deactivateOperator(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id,
    uint256 _deactivedId
  ) external onlyMaintainer(_DATASTORE, _id) returns (bool) {
    if (_DATASTORE.readUintForId(_id, "activeOperator") == _deactivedId)
      _DATASTORE.writeUintForId(_id, "activeOperator", 0);

    _DATASTORE.writeUintForId(
      _id,
      bytes32(
        keccak256(abi.encodePacked(_deactivedId, "activationExpiration"))
      ),
      block.timestamp + DEACTIVATION_PERIOD //15 days
    );
    emit OperatorDeactivated(_id, _deactivedId);
    return true;
  }

  /**
   * @notice Only an Operator is expected to pay for the DEBT of a staking pool.
   * When it is paid, p subChain balance decreases, effectively changing the price calculations!
   */
  function payDebt(
    StakePool storage self,
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _poolId,
    uint256 _operatorId
  )
    external
    onlyMaintainer(_DATASTORE, _operatorId)
    beforeActivationExpiration(_DATASTORE, _poolId, _operatorId)
  {
    require(
      !_isOracleActive(_DATASTORE, _poolId),
      "StakeUtils: Oracle is active"
    );

    //mgs.value should be bigger than 0 for everything to make sense
    require(msg.value > 0, "StakeUtils: no avax is sent");

    // msg.value is assined to value, value is the variable to keep how much left in my hand to continue
    // paying the rest of the debts and or how much left after paying the debts to put the rest in to surplus
    uint256 value = msg.value;
    uint256 surplus = _DATASTORE.readUintForId(_poolId, "surplus");

    // this if statement checks if there is a operation fee that needs to be paid.
    // If distributed fee exceeds the surplus, there is a gap between fees and surplus
    // so we check if the unclaimedFees are bigger than surplus.
    if (
      _DATASTORE.readUintForId(_poolId, "unclaimedFees") >
      _DATASTORE.readUintForId(_poolId, "surplus")
    ) {
      // the difference between unclaimedFees and the surplus is the debt for the fees.
      uint256 debtInFees = _DATASTORE.readUintForId(_poolId, "unclaimedFees") -
        _DATASTORE.readUintForId(_poolId, "surplus");

      // need to check if the debtInFees is bigger than the value, if not, can only pay value amount of debtInFees
      // if not, we are paying all debtInFees by adding it to the surplus so that the difference might be 0(zero) after this action.
      if (debtInFees > value) {
        debtInFees = value;
      }

      // we pay for the debtInFees as we can
      surplus += debtInFees;

      // we substract the debtInFees from value since we cannot use that amount to pay the rest, it is already gone.
      value -= debtInFees;
    }

    // we check if remaining value is bigger than 0 to save gas, because it may be already used
    if (value > 0) {
      // we get the debt from the withdrawal pool
      uint256 debtToBurn = withdrawalPoolById(_DATASTORE, _poolId).getDebt();
      // to save the gas we make sure that it is bigger then an ignorably low amount while we are doing a buyback
      if (debtToBurn > IGNORABLE_DEBT) {
        // same idea with the fee debt and values
        if (debtToBurn > value) {
          debtToBurn = value;
        }

        // burns
        _buyback(
          self,
          _DATASTORE,
          address(0),
          _poolId,
          debtToBurn,
          0,
          type(uint256).max
        );

        // we substract the debt from value to see how much left if there is any left to put it on surplus
        value -= debtToBurn;
      }

      // to save gas we are making sure that value is bigger than zero and if so, we add it to the surplus.
      if (value > 0) {
        surplus += value;
      }
    }

    _DATASTORE.writeUintForId(_poolId, "surplus", surplus + value);

    // in all cases, if we pass the require msg.value > 0, that money is coming from the p chain
    // and we need to decrease the pBalance for msg.value amount
    uint256 pBalance = _DATASTORE.readUintForId(_poolId, "pBalance");
    if (pBalance > msg.value) {
      _DATASTORE.writeUintForId(_poolId, "pBalance", pBalance - msg.value);
    } else {
      _DATASTORE.writeUintForId(_poolId, "pBalance", 0);
    }

    emit debtPaid(_poolId, _operatorId, msg.value);
  }

  /**
   * @notice only authorized Operator is expected to claim the surplus of a staking pool
   * @notice current fees are not allowed to be claimed from surplus,
   * however oracle update can also make it hard since it increases unclaimedFees without touching the surplus
   */
  function claimSurplus(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _poolId,
    uint256 _claimerId
  )
    external
    onlyMaintainer(_DATASTORE, _claimerId)
    beforeActivationExpiration(_DATASTORE, _poolId, _claimerId)
    returns (bool)
  {
    require(
      !_isOracleActive(_DATASTORE, _poolId),
      "StakeUtils: Oracle is active"
    );
    uint256 fees = _DATASTORE.readUintForId(_poolId, "unclaimedFees");
    uint256 surplus = _DATASTORE.readUintForId(_poolId, "surplus");
    require(surplus > fees, "StakeUtils: pool fees exceed surplus");
    _DATASTORE.writeUintForId(_poolId, "surplus", fees);

    uint256 currentPBal = _DATASTORE.readUintForId(_poolId, "pBalance");
    _DATASTORE.writeUintForId(
      _poolId,
      "pBalance",
      currentPBal + surplus - fees
    );

    (bool sent, ) = payable(
      _DATASTORE.readAddressForId(_claimerId, "maintainer")
    ).call{ value: surplus - fees }("");
    require(sent, "StakeUtils: Failed to send Avax");
    emit SurplusClaimed(_poolId, surplus - fees);
    return sent;
  }

  /**
   * @notice accumulatedFee is stored with a key combines the poolId, claimerId & "accumulatedFee"
   * @dev function also returns the key for ease of use, please use.
   */
  function accumulatedFee(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 poolId,
    uint256 claimerId
  ) public view returns (uint256 fee, bytes32 key) {
    key = bytes32(keccak256(abi.encodePacked(claimerId, "accumulatedFee")));
    fee = _DATASTORE.readUintForId(poolId, key);
  }

  /**
   * @notice anyone can call this function, but it sends AVAX to maintainer.
   * @notice reverts if there are not enough surplus.
   */
  function claimFee(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 poolId,
    uint256 claimerId
  )
    external
    beforeActivationExpiration(_DATASTORE, poolId, claimerId)
    returns (uint256 feeToSend)
  {
    require(
      !_isOracleActive(_DATASTORE, poolId),
      "StakeUtils: Oracle is active"
    );
    (uint256 fee, bytes32 key) = accumulatedFee(_DATASTORE, poolId, claimerId);

    uint256 surplus = _DATASTORE.readUintForId(poolId, "surplus");
    require(
      fee > 0 && surplus > 0,
      "StakeUtils: fee and surplus should be bigger than zero"
    );

    feeToSend = fee > surplus ? surplus : fee;
    _DATASTORE.writeUintForId(poolId, "surplus", surplus - feeToSend);
    uint256 _unclaimedFees = _DATASTORE.readUintForId(poolId, "unclaimedFees");

    _DATASTORE.writeUintForId(
      poolId,
      "unclaimedFees",
      _unclaimedFees - feeToSend
    );

    address receiver = payable(
      _DATASTORE.readAddressForId(claimerId, "maintainer")
    );

    // set the accumulatedFee to zero
    _DATASTORE.writeUintForId(poolId, key, fee - feeToSend);

    (bool sent, ) = receiver.call{ value: feeToSend }("");
    require(sent, "StakeUtils: Failed to send Avax");
    emit FeeClaimed(poolId, claimerId, feeToSend);
  }

  /**
   * @notice                      ** WITHDRAWAL POOL specific functions **
   */

  function isStakingPausedForPool(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id
  ) public view returns (bool) {
    // minting is paused when length != 0
    return _DATASTORE.readBytesForId(_id, "stakePaused").length != 0;
  }

  /**
   * @notice pausing only prevents new staking operations.
   * when a pool is paused for staking there are NO new funds to be minted, NO surplus.
   */
  function pauseStakingForPool(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id
  ) external onlyMaintainer(_DATASTORE, _id) {
    _DATASTORE.writeBytesForId(_id, "stakePaused", bytes("1")); // meaning true, importantly length > 0
    emit PausedPool(_id);
  }

  function unpauseStakingForPool(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id
  ) external onlyMaintainer(_DATASTORE, _id) {
    _DATASTORE.writeBytesForId(_id, "stakePaused", bytes("")); // meaning false, importantly length = 0
    emit UnpausedPool(_id);
  }

  function withdrawalPoolById(
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id
  ) public view returns (ISwap) {
    return ISwap(_DATASTORE.readAddressForId(_id, "withdrawalPool"));
  }

  function LPTokenById(DataStoreUtils.DataStore storage _DATASTORE, uint256 _id)
    public
    view
    returns (LPToken)
  {
    return LPToken(_DATASTORE.readAddressForId(_id, "LPToken"));
  }

  /**
   * @notice deploys a new withdrawal pool using DEFAULT_SWAP_POOL
   * @dev sets the withdrawal pool with respective
   */
  function deployWithdrawalPool(
    StakePool storage self,
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 _id
  ) external returns (address WithdrawalPool) {
    require(_id > 0, "StakeUtils: id should be > 0");
    require(
      _DATASTORE.readAddressForId(_id, "withdrawalPool") == address(0),
      "StakeUtils: withdrawalPool already exists"
    );

    WithdrawalPool = _clone(self.DEFAULT_SWAP_POOL);

    address _LPToken = ISwap(WithdrawalPool).initialize(
      address(getgAVAX(self)),
      _id,
      string(
        abi.encodePacked(
          _DATASTORE.readBytesForId(_id, "name"),
          "-Geode WP Token"
        )
      ),
      string(abi.encodePacked(_DATASTORE.readBytesForId(_id, "name"), "-WP")),
      self.DEFAULT_A,
      self.DEFAULT_FEE,
      self.DEFAULT_ADMIN_FEE,
      self.DEFAULT_LP_TOKEN
    );

    // initially 1 AVAX = 1 AVAX
    _setPricePerShare(self, 1 ether, _id);
    _DATASTORE.writeAddressForId(_id, "withdrawalPool", WithdrawalPool);
    _DATASTORE.writeAddressForId(_id, "LPToken", _LPToken);

    // approve token so we can use it in buybacks
    getgAVAX(self).setApprovalForAll(WithdrawalPool, true);
    LPTokenById(_DATASTORE, _id).approve(WithdrawalPool, type(uint256).max);
  }

  /**
   * @notice staking function. buys if price is low, mints new tokens if a surplus is sent (extra avax through msg.value)
   * @param poolId id of the staking pool, withdrawal pool and gAVAX to be used.
   * @param minGavax swap op param
   * @param deadline swap op param
    // d  m.v
    // 100 10 => buyback
    // 100 100  => buyback
    // 10 100  =>  buyback + mint
    // 0 x => mint
   */
  function stake(
    StakePool storage self,
    DataStoreUtils.DataStore storage _DATASTORE,
    uint256 poolId,
    uint256 minGavax,
    uint256 deadline
  ) external returns (uint256 totalgAvax) {
    require(msg.value > 0, "GeodePortal: no avax given");
    require(
      !isStakingPausedForPool(_DATASTORE, poolId),
      "StakeUtils: minting is paused"
    );
    uint256 debt = withdrawalPoolById(_DATASTORE, poolId).getDebt();
    if (debt >= msg.value) {
      return
        _buyback(
          self,
          _DATASTORE,
          msg.sender,
          poolId,
          msg.value,
          minGavax,
          deadline
        );
    } else {
      uint256 boughtGavax = 0;
      if (debt > IGNORABLE_DEBT) {
        boughtGavax = _buyback(
          self,
          _DATASTORE,
          msg.sender,
          poolId,
          debt,
          0,
          deadline
        );
      }
      uint256 remAvax = msg.value - debt;
      uint256 mintGavax = (
        ((remAvax * gAVAX_DENOMINATOR) / oraclePrice(self, poolId))
      );
      _mint(self.gAVAX, msg.sender, poolId, mintGavax);
      _DATASTORE.writeUintForId(
        poolId,
        "surplus",
        _DATASTORE.readUintForId(poolId, "surplus") + remAvax
      );
      require(
        boughtGavax + mintGavax >= minGavax,
        "StakeUtils: less than minGavax"
      );
      return boughtGavax + mintGavax;
    }
  }
}

File 2 of 14 : Clones.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/Clones.sol)

pragma solidity ^0.8.0;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
 * deploying minimal proxy contracts, also known as "clones".
 *
 * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
 * > a minimal bytecode implementation that delegates all calls to a known, fixed address.
 *
 * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
 * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
 * deterministic method.
 *
 * _Available since v3.4._
 */
library Clones {
    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create opcode, which should never revert.
     */
    function clone(address implementation) internal returns (address instance) {
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(ptr, 0x14), shl(0x60, implementation))
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
            instance := create(0, ptr, 0x37)
        }
        require(instance != address(0), "ERC1167: create failed");
    }

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create2 opcode and a `salt` to deterministically deploy
     * the clone. Using the same `implementation` and `salt` multiple time will revert, since
     * the clones cannot be deployed twice at the same address.
     */
    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(ptr, 0x14), shl(0x60, implementation))
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
            instance := create2(0, ptr, 0x37, salt)
        }
        require(instance != address(0), "ERC1167: create2 failed");
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt,
        address deployer
    ) internal pure returns (address predicted) {
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(ptr, 0x14), shl(0x60, implementation))
            mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
            mstore(add(ptr, 0x38), shl(0x60, deployer))
            mstore(add(ptr, 0x4c), salt)
            mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
            predicted := keccak256(add(ptr, 0x37), 0x55)
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(address implementation, bytes32 salt)
        internal
        view
        returns (address predicted)
    {
        return predictDeterministicAddress(implementation, salt, address(this));
    }
}

File 3 of 14 : ISwap.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.7;

import "./IgAVAX.sol";

interface ISwap {
  // pool data view functions
  function getERC1155() external view returns (address);

  function getA() external view returns (uint256);

  function getAPrecise() external view returns (uint256);

  function getToken() external view returns (uint256);

  function getTokenBalance(uint8 index) external view returns (uint256);

  function getVirtualPrice() external view returns (uint256);

  function getDebt() external view returns (uint256);

  function getAdminBalance(uint256 index) external view returns (uint256);

  // min return calculation functions
  function calculateSwap(
    uint8 tokenIndexFrom,
    uint8 tokenIndexTo,
    uint256 dx
  ) external view returns (uint256);

  function calculateTokenAmount(uint256[] calldata amounts, bool deposit)
    external
    view
    returns (uint256);

  function calculateRemoveLiquidity(uint256 amount)
    external
    view
    returns (uint256[] memory);

  function calculateRemoveLiquidityOneToken(
    uint256 tokenAmount,
    uint8 tokenIndex
  ) external view returns (uint256 availableTokenAmount);

  // state modifying functions
  function initialize(
    address _gAvax,
    uint256 _pooledTokenId,
    string memory lpTokenName,
    string memory lpTokenSymbol,
    uint256 _a,
    uint256 _fee,
    uint256 _adminFee,
    address lpTokenTargetAddress
  ) external returns (address lpToken);

  function swap(
    uint8 tokenIndexFrom,
    uint8 tokenIndexTo,
    uint256 dx,
    uint256 minDy,
    uint256 deadline
  ) external payable returns (uint256);

  function addLiquidity(
    uint256[] calldata amounts,
    uint256 minToMint,
    uint256 deadline
  ) external payable returns (uint256);

  function removeLiquidity(
    uint256 amount,
    uint256[] calldata minAmounts,
    uint256 deadline
  ) external returns (uint256[] memory);

  function removeLiquidityOneToken(
    uint256 tokenAmount,
    uint8 tokenIndex,
    uint256 minAmount,
    uint256 deadline
  ) external returns (uint256);

  function removeLiquidityImbalance(
    uint256[] calldata amounts,
    uint256 maxBurnAmount,
    uint256 deadline
  ) external returns (uint256);

  function withdrawAdminFees() external;

  function setAdminFee(uint256 newAdminFee) external;

  function setSwapFee(uint256 newSwapFee) external;

  function rampA(uint256 futureA, uint256 futureTime) external;

  function stopRampA() external;
}

File 4 of 14 : IgAVAX.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.8.7;

interface IgAVAX {
  function supportsInterface(bytes4 interfaceId) external view returns (bool);

  function uri(uint256) external view returns (string memory);

  function balanceOf(address account, uint256 id)
    external
    view
    returns (uint256);

  function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
    external
    view
    returns (uint256[] memory);

  function setApprovalForAll(address operator, bool approved) external;

  function isApprovedForAll(address account, address operator)
    external
    view
    returns (bool);

  function safeTransferFrom(
    address from,
    address to,
    uint256 id,
    uint256 amount,
    bytes memory data
  ) external;

  function safeBatchTransferFrom(
    address from,
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory data
  ) external;

  function burn(
    address account,
    uint256 id,
    uint256 value
  ) external;

  function burnBatch(
    address account,
    uint256[] memory ids,
    uint256[] memory values
  ) external;

  function totalSupply(uint256 id) external view returns (uint256);

  function exists(uint256 id) external view returns (bool);

  function mint(
    address to,
    uint256 id,
    uint256 amount,
    bytes memory data
  ) external;

  function mintBatch(
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory data
  ) external;

  function pause() external;

  function unpause() external;

  function pricePerShare(uint256 _id) external view returns (uint256);

  function setPricePerShare(uint256 pricePerShare_, uint256 _id) external;

  function isInterface(address operator, uint256 id)
    external
    view
    returns (bool);

  function setInterface(
    address _Interface,
    uint256 _id,
    bool isSet
  ) external;
}

File 5 of 14 : LPToken.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.7;

import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/**
 * @title Liquidity Provider Token
 * @notice This token is an ERC20 detailed token with added capability to be minted by the owner.
 * It is used to represent user's shares when providing liquidity to swap contracts.
 * @dev Only Swap contracts should initialize and own LPToken contracts.
 */
contract LPToken is ERC20BurnableUpgradeable, OwnableUpgradeable {
  /**
   * @notice Initializes this LPToken contract with the given name and symbol
   * @dev The caller of this function will become the owner. A Swap contract should call this
   * in its initializer function.
   * @param name name of this token
   * @param symbol symbol of this token
   */
  function initialize(string memory name, string memory symbol)
    external
    initializer
    returns (bool)
  {
    __Context_init_unchained();
    __ERC20_init_unchained(name, symbol);
    __Ownable_init_unchained();
    return true;
  }

  /**
   * @notice Mints the given amount of LPToken to the recipient.
   * @dev only owner can call this mint function
   * @param recipient address of account to receive the tokens
   * @param amount amount of tokens to mint
   */
  function mint(address recipient, uint256 amount) external onlyOwner {
    require(amount != 0, "LPToken: cannot mint 0");
    _mint(recipient, amount);
  }

  /**
   * @dev Overrides ERC20._beforeTokenTransfer() which get called on every transfers including
   * minting and burning. This ensures that Swap.updateUserWithdrawFees are called everytime.
   * This assumes the owner is set to a Swap contract's address.
   */
  function _beforeTokenTransfer(
    address from,
    address to,
    uint256 amount
  ) internal virtual override(ERC20Upgradeable) {
    super._beforeTokenTransfer(from, to, amount);
    require(to != address(this), "LPToken: cannot send to itself");
  }
}

File 6 of 14 : DataStoreLib.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.7;

/**
 * @title Storage Management library for dynamic structs based on data types
 *
 * DataStoreUtils is a storage management tool designed to create a safe and scalable
 * storage layout with the help of ids and keys.
 * Mainly focusing on upgradable contracts with multiple user types to create a
 * sustainable development environment.
 *
 * In summary, extra gas cost that would be saved with Storage packing are
 * ignored to create upgradable structs.
 *
 * IDs are the representation of a user with any given key as properties.
 * Type for ID is not mandatory, not all IDs should have an explicit type.
 * Thus there is no checks of types or keys.
 *
 * @notice distinct id and key pairs return different storage slots
 *
 */
library DataStoreUtils {
  /**
   * @notice Main Struct for reading and writing data to storage for given id+key pairs
   * @param allIdsByType optional categorization for given ID, requires direct access, type => id[]
   * @param uintData keccak(id, key) =>  returns uint256
   * @param bytesData keccak(id, key) => returns bytes
   * @param addressData keccak(id, key) =>  returns address
   * NOTE any other storage type can be expressed as bytes
   */
  struct DataStore {
    mapping(uint256 => uint256[]) allIdsByType;
    mapping(bytes32 => uint256) uintData;
    mapping(bytes32 => bytes) bytesData;
    mapping(bytes32 => address) addressData;
  }

  /**
   * **DATA GETTERS **
   **/
  function readUintForId(
    DataStore storage self,
    uint256 _id,
    bytes32 _key
  ) public view returns (uint256 data) {
    data = self.uintData[keccak256(abi.encodePacked(_id, _key))];
  }

  function readBytesForId(
    DataStore storage self,
    uint256 _id,
    bytes32 _key
  ) public view returns (bytes memory data) {
    data = self.bytesData[keccak256(abi.encodePacked(_id, _key))];
  }

  function readAddressForId(
    DataStore storage self,
    uint256 _id,
    bytes32 _key
  ) public view returns (address data) {
    data = self.addressData[keccak256(abi.encodePacked(_id, _key))];
  }

  /**
   * **DATA SETTERS **
   **/
  function writeUintForId(
    DataStore storage self,
    uint256 _id,
    bytes32 _key,
    uint256 data
  ) public {
    self.uintData[keccak256(abi.encodePacked(_id, _key))] = data;
  }

  function writeBytesForId(
    DataStore storage self,
    uint256 _id,
    bytes32 _key,
    bytes memory data
  ) public {
    self.bytesData[keccak256(abi.encodePacked(_id, _key))] = data;
  }

  function writeAddressForId(
    DataStore storage self,
    uint256 _id,
    bytes32 _key,
    address data
  ) public {
    self.addressData[keccak256(abi.encodePacked(_id, _key))] = data;
  }
}

File 7 of 14 : ERC20BurnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol)

pragma solidity ^0.8.0;

import "../ERC20Upgradeable.sol";
import "../../../utils/ContextUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20BurnableUpgradeable is Initializable, ContextUpgradeable, ERC20Upgradeable {
    function __ERC20Burnable_init() internal onlyInitializing {
    }

    function __ERC20Burnable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        _spendAllowance(account, _msgSender(), amount);
        _burn(account, amount);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 8 of 14 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

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

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 9 of 14 : ERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
        __ERC20_init_unchained(name_, symbol_);
    }

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, _allowances[owner][spender] + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = _allowances[owner][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Spend `amount` form the allowance of `owner` toward `spender`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[45] private __gap;
}

File 10 of 14 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 11 of 14 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} modifier, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

File 12 of 14 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

    /**
     * @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 13 of 14 : IERC20MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 14 of 14 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {
    "contracts/Portal/utils/DataStoreLib.sol": {
      "DataStoreUtils": "0xc7332d9abef755c42b4df9d9db09beef15f8f9fb"
    }
  }
}

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"claimerId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newSurplus","type":"uint256"}],"name":"FeeClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"MaintainerFeeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newMaxFee","type":"uint256"}],"name":"MaxMaintainerFeeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"activeOperator","type":"uint256"}],"name":"OperatorActivated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"deactiveOperator","type":"uint256"}],"name":"OperatorDeactivated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newPBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"distributedFeeTotal","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"updateTimeStamp","type":"uint256"}],"name":"OracleUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"}],"name":"PausedPool","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"pricePerShare","type":"uint256"}],"name":"PriceChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newSurplus","type":"uint256"}],"name":"SurplusClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"}],"name":"UnpausedPool","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"operatorId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"paidDebt","type":"uint256"}],"name":"debtPaid","type":"event"}]

61497261003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106101415760003560e01c80636b4a7685116100c2578063b86aaf8211610086578063b86aaf8214610337578063d163f89a14610357578063d965692d1461036a578063e7345b6914610392578063fd34c1c0146103b2578063fdf454fa146103c557600080fd5b80636b4a7685146102a45780636ecc8965146102c457806385c56cc5146102e457806386a51db5146102f75780639e8c22831461031757600080fd5b80633c9caf1c116101095780633c9caf1c146102235780633f4cdcda14610236578063538b984f1461025157806355e66bad14610264578063569391b61461028457600080fd5b8063053b592e146101465780630700d74b1461017957806313fec1c01461019b5780632f11d002146101bb57806334e86093146101eb575b600080fd5b81801561015257600080fd5b506101666101613660046144d1565b6103e5565b6040519081526020015b60405180910390f35b81801561018557600080fd5b50610199610194366004614369565b610707565b005b8180156101a757600080fd5b506101666101b63660046143c4565b610799565b8180156101c757600080fd5b506101db6101d63660046143c4565b610d78565b6040519015158152602001610170565b8180156101f757600080fd5b5061020b61020636600461426b565b6113b1565b6040516001600160a01b039091168152602001610170565b61020b610231366004614369565b6113c2565b61020b6102443660046143f0565b546001600160a01b031690565b61016661025f366004614369565b611467565b81801561027057600080fd5b5061019961027f36600461438b565b6114f7565b81801561029057600080fd5b5061019961029f366004614369565b6116f1565b8180156102b057600080fd5b5061020b6102bf3660046143c4565b611865565b8180156102d057600080fd5b506101db6102df3660046143c4565b611e4a565b6101db6102f2366004614369565b61207d565b81801561030357600080fd5b50610199610312366004614409565b61212c565b81801561032357600080fd5b50610199610332366004614369565b61293d565b81801561034357600080fd5b5061016661035236600461443b565b612a9a565b6101666103653660046143c4565b613056565b61037d6103783660046143c4565b6131a3565b60408051928352602083019190915201610170565b81801561039e57600080fd5b506101db6103ad3660046143c4565b613283565b61020b6103c0366004614369565b613558565b8180156103d157600080fd5b506101996103e0366004614409565b6135b1565b600080341161043b5760405162461bcd60e51b815260206004820152601a60248201527f47656f6465506f7274616c3a206e6f206176617820676976656e00000000000060448201526064015b60405180910390fd5b610445858561207d565b156104925760405162461bcd60e51b815260206004820152601d60248201527f5374616b655574696c733a206d696e74696e67206973207061757365640000006044820152606401610432565b600061049e8686613558565b6001600160a01b03166314a6bf0f6040518163ffffffff1660e01b815260040160206040518083038186803b1580156104d657600080fd5b505afa1580156104ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061050e919061450c565b905034811061052e5761052687873388348989613784565b9150506106fe565b6000670de0b6b3a764000082111561055357610550888833898660008a613784565b90505b600061055f8334614856565b9050600061056d8a89611467565b61057f670de0b6b3a764000084614837565b6105899190614823565b8a549091506105a3906001600160a01b0316338a84613949565b60405163f237bab360e01b815273c7332d9abef755c42b4df9d9db09beef15f8f9fb90638efea400908b908b908690859063f237bab3906105ea90869086906004016147c7565b60206040518083038186803b15801561060257600080fd5b505af4158015610616573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063a919061450c565b610644919061480b565b6040518463ffffffff1660e01b8152600401610662939291906147e5565b60006040518083038186803b15801561067a57600080fd5b505af415801561068e573d6000803e3d6000fd5b5050505086818461069f919061480b565b10156106ed5760405162461bcd60e51b815260206004820152601e60248201527f5374616b655574696c733a206c657373207468616e206d696e476176617800006044820152606401610432565b6106f7818461480b565b9450505050505b95945050505050565b816007015481111561075b5760405162461bcd60e51b815260206004820152601e60248201527f5374616b655574696c733a20666565206d6f7265207468616e203130302500006044820152606401610432565b600982018190556040518181527f885da6736df929c01d726b95426cc170346a259f1cfbd6b238f37fc58f420cfa9060200160405180910390a15050565b6000838383428373c7332d9abef755c42b4df9d9db09beef15f8f9fb63f237bab3909185856040516020016107ce91906145ab565b604051602081830303815290604052805190602001206040518463ffffffff1660e01b8152600401610813939291909283526020830191909152604082015260600190565b60206040518083038186803b15801561082b57600080fd5b505af415801561083f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610863919061450c565b116108805760405162461bcd60e51b81526004016104329061463d565b61088a8787613a21565b156108a75760405162461bcd60e51b815260040161043290614691565b6000806108b58989896131a3565b60405163f237bab360e01b8152919350915060009073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab3906108f6908d908d906004016147c7565b60206040518083038186803b15801561090e57600080fd5b505af4158015610922573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610946919061450c565b90506000831180156109585750600081115b6109c35760405162461bcd60e51b815260206004820152603660248201527f5374616b655574696c733a2066656520616e6420737572706c75732073686f756044820152756c6420626520626967676572207468616e207a65726f60501b6064820152608401610432565b8083116109d057826109d2565b805b965073c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea4008b8b6109fa8b86614856565b6040518463ffffffff1660e01b8152600401610a18939291906147e5565b60006040518083038186803b158015610a3057600080fd5b505af4158015610a44573d6000803e3d6000fd5b505060405163f237bab360e01b81526000925073c7332d9abef755c42b4df9d9db09beef15f8f9fb915063f237bab390610a84908e908e90600401614709565b60206040518083038186803b158015610a9c57600080fd5b505af4158015610ab0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ad4919061450c565b905073c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea4008c8c610afc8c86614856565b6040516001600160e01b031960e086901b168152600481019390935260248301919091526c756e636c61696d65644665657360981b6044830152606482015260840160006040518083038186803b158015610b5657600080fd5b505af4158015610b6a573d6000803e3d6000fd5b5050604051630143c90b60e71b81526000925073c7332d9abef755c42b4df9d9db09beef15f8f9fb915063a1e4858090610baa908f908e90600401614760565b60206040518083038186803b158015610bc257600080fd5b505af4158015610bd6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bfa9190614288565b905073c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea4008d8d87610c238e8b614856565b6040516001600160e01b031960e087901b168152600481019490945260248401929092526044830152606482015260840160006040518083038186803b158015610c6c57600080fd5b505af4158015610c80573d6000803e3d6000fd5b505050506000816001600160a01b03168a60405160006040518083038185875af1925050503d8060008114610cd1576040519150601f19603f3d011682016040523d82523d6000602084013e610cd6565b606091505b5050905080610d275760405162461bcd60e51b815260206004820152601f60248201527f5374616b655574696c733a204661696c656420746f2073656e642041766178006044820152606401610432565b604080518d8152602081018d90529081018b90527f25722fddd3d0eee26ce8297d72e7b76fce040b1b7e9c3243ccfec84b0f3f24509060600160405180910390a15050505050505050509392505050565b604051630143c90b60e71b815260009084908390339073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e4858090610dba9086908690600401614760565b60206040518083038186803b158015610dd257600080fd5b505af4158015610de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e0a9190614288565b6001600160a01b031614610e305760405162461bcd60e51b8152600401610432906146c8565b858585428373c7332d9abef755c42b4df9d9db09beef15f8f9fb63f237bab390918585604051602001610e6391906145ab565b604051602081830303815290604052805190602001206040518463ffffffff1660e01b8152600401610ea8939291909283526020830191909152604082015260600190565b60206040518083038186803b158015610ec057600080fd5b505af4158015610ed4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef8919061450c565b11610f155760405162461bcd60e51b81526004016104329061463d565b610f1f8989613a21565b15610f3c5760405162461bcd60e51b815260040161043290614691565b60405163f237bab360e01b815260009073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab390610f78908d908d90600401614709565b60206040518083038186803b158015610f9057600080fd5b505af4158015610fa4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fc8919061450c565b60405163f237bab360e01b815290915060009073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab390611007908e908e906004016147c7565b60206040518083038186803b15801561101f57600080fd5b505af4158015611033573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611057919061450c565b90508181116110b45760405162461bcd60e51b8152602060048201526024808201527f5374616b655574696c733a20706f6f6c20666565732065786365656420737572604482015263706c757360e01b6064820152608401610432565b6040516223bfa960ea1b815273c7332d9abef755c42b4df9d9db09beef15f8f9fb90638efea400906110ee908e908e9087906004016147e5565b60006040518083038186803b15801561110657600080fd5b505af415801561111a573d6000803e3d6000fd5b505060405163f237bab360e01b81526000925073c7332d9abef755c42b4df9d9db09beef15f8f9fb915063f237bab39061115a908f908f90600401614781565b60206040518083038186803b15801561117257600080fd5b505af4158015611186573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111aa919061450c565b905073c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea4008d8d866111d3878761480b565b6111dd9190614856565b6040518463ffffffff1660e01b81526004016111fb939291906147a0565b60006040518083038186803b15801561121357600080fd5b505af4158015611227573d6000803e3d6000fd5b5050505060008c73c7332d9abef755c42b4df9d9db09beef15f8f9fb63a1e4858090918d6040518363ffffffff1660e01b8152600401611268929190614760565b60206040518083038186803b15801561128057600080fd5b505af4158015611294573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112b89190614288565b6001600160a01b03166112cb8585614856565b604051600081818185875af1925050503d8060008114611307576040519150601f19603f3d011682016040523d82523d6000602084013e61130c565b606091505b505090508061135d5760405162461bcd60e51b815260206004820152601f60248201527f5374616b655574696c733a204661696c656420746f2073656e642041766178006044820152606401610432565b7fe72e921f860b05525da6c01e054f27683e8b04c1c82ef4335cc414a63c3f15198c6113898686614856565b6040805192835260208301919091520160405180910390a19c9b505050505050505050505050565b60006113bc82613af8565b92915050565b604051630143c90b60e71b815260048101839052602481018290526626282a37b5b2b760c91b604482015260009073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e48580906064015b60206040518083038186803b15801561142857600080fd5b505af415801561143c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114609190614288565b9392505050565b600061147a83546001600160a01b031690565b6001600160a01b031663f759cc3b836040518263ffffffff1660e01b81526004016114a791815260200190565b60206040518083038186803b1580156114bf57600080fd5b505afa1580156114d3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611460919061450c565b604051630143c90b60e71b815260048101849052602481018390526921a7a72a2927a62622a960b11b6044820152339073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e485809060640160206040518083038186803b15801561155e57600080fd5b505af4158015611572573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115969190614288565b6001600160a01b0316146115fb5760405162461bcd60e51b815260206004820152602660248201527f5374616b655574696c733a206e6f7420434f4e54524f4c4c4552206f662067696044820152651d995b881a5960d21b6064820152608401610432565b6001600160a01b0381166116605760405162461bcd60e51b815260206004820152602660248201527f5374616b655574696c733a206d61696e7461696e65722063616e206e6f74206260448201526565207a65726f60d01b6064820152608401610432565b60405163dff34ff160e01b815260048101849052602481018390526936b0b4b73a30b4b732b960b11b60448201526001600160a01b038216606482015273c7332d9abef755c42b4df9d9db09beef15f8f9fb9063dff34ff19060840160006040518083038186803b1580156116d457600080fd5b505af41580156116e8573d6000803e3d6000fd5b50505050505050565b604051630143c90b60e71b815282908290339073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e48580906117309086908690600401614760565b60206040518083038186803b15801561174857600080fd5b505af415801561175c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117809190614288565b6001600160a01b0316146117a65760405162461bcd60e51b8152600401610432906146c8565b60408051808201825260018152603160f81b60208201529051630eee4dd960e41b815273c7332d9abef755c42b4df9d9db09beef15f8f9fb9163eee4dd90916117f691889188919060040161472d565b60006040518083038186803b15801561180e57600080fd5b505af4158015611822573d6000803e3d6000fd5b505050507fcf61a69571fcb149379b9264df303e430a464346ff265a1bf29782c491aba6d58360405161185791815260200190565b60405180910390a150505050565b60008082116118b65760405162461bcd60e51b815260206004820152601c60248201527f5374616b655574696c733a2069642073686f756c64206265203e2030000000006044820152606401610432565b604051630143c90b60e71b815260048101849052602481018390526d1dda5d1a191c985dd85b141bdbdb60921b604482015260009073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e485809060640160206040518083038186803b15801561192257600080fd5b505af4158015611936573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061195a9190614288565b6001600160a01b0316146119c25760405162461bcd60e51b815260206004820152602960248201527f5374616b655574696c733a207769746864726177616c506f6f6c20616c72656160448201526864792065786973747360b81b6064820152608401610432565b60018401546119d9906001600160a01b03166113b1565b90506000816001600160a01b031663303e9bea6119fd87546001600160a01b031690565b6040516301ae508b60e11b81526004810188905260248101879052636e616d6560e01b6044820152869073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063035ca1169060640160006040518083038186803b158015611a5e57600080fd5b505af4158015611a72573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a9a91908101906142c7565b604051602001611aaa9190614551565b60408051808303601f19018152908290526301ae508b60e11b8252600482018a905260248201899052636e616d6560e01b60448301529073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063035ca1169060640160006040518083038186803b158015611b1857600080fd5b505af4158015611b2c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611b5491908101906142c7565b604051602001611b649190614584565b6040516020818303038152906040528a600401548b600501548c600601548d60020160009054906101000a90046001600160a01b03166040518963ffffffff1660e01b8152600401611bbd9897969594939291906145d1565b602060405180830381600087803b158015611bd757600080fd5b505af1158015611beb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c0f9190614288565b9050611c2485670de0b6b3a764000085613b95565b60405163dff34ff160e01b815260048101859052602481018490526d1dda5d1a191c985dd85b141bdbdb60921b60448201526001600160a01b038316606482015273c7332d9abef755c42b4df9d9db09beef15f8f9fb9063dff34ff19060840160006040518083038186803b158015611c9c57600080fd5b505af4158015611cb0573d6000803e3d6000fd5b505060405163dff34ff160e01b815260048101879052602481018690526626282a37b5b2b760c91b60448201526001600160a01b038416606482015273c7332d9abef755c42b4df9d9db09beef15f8f9fb925063dff34ff1915060840160006040518083038186803b158015611d2557600080fd5b505af4158015611d39573d6000803e3d6000fd5b50505050611d4e85546001600160a01b031690565b60405163a22cb46560e01b81526001600160a01b03848116600483015260016024830152919091169063a22cb46590604401600060405180830381600087803b158015611d9a57600080fd5b505af1158015611dae573d6000803e3d6000fd5b50505050611dbc84846113c2565b60405163095ea7b360e01b81526001600160a01b0384811660048301526000196024830152919091169063095ea7b390604401602060405180830381600087803b158015611e0957600080fd5b505af1158015611e1d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e4191906142a5565b50509392505050565b604051630143c90b60e71b815260009084908490339073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e4858090611e8c9086908690600401614760565b60206040518083038186803b158015611ea457600080fd5b505af4158015611eb8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611edc9190614288565b6001600160a01b031614611f025760405162461bcd60e51b8152600401610432906146c8565b6040516223bfa960ea1b815260048101879052602481018690526d30b1ba34bb32a7b832b930ba37b960911b60448201526064810185905273c7332d9abef755c42b4df9d9db09beef15f8f9fb90638efea4009060840160006040518083038186803b158015611f7157600080fd5b505af4158015611f85573d6000803e3d6000fd5b505050508573c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea40090918787604051602001611fb891906145ab565b604051602081830303815290604052805190602001206000196040518563ffffffff1660e01b8152600401612006949392919093845260208401929092526040830152606082015260800190565b60006040518083038186803b15801561201e57600080fd5b505af4158015612032573d6000803e3d6000fd5b505060408051888152602081018890527f21a1f9712a3958e2b18cbc36d5d46385602f172ccabcb4948e557731a3a7423193500190505b60405180910390a150600195945050505050565b6040516301ae508b60e11b815260048101839052602481018290526a1cdd185ad954185d5cd95960aa1b604482015260009073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063035ca1169060640160006040518083038186803b1580156120e657600080fd5b505af41580156120fa573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261212291908101906142c7565b5115159392505050565b604051630143c90b60e71b815283908290339073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e485809061216b9086908690600401614760565b60206040518083038186803b15801561218357600080fd5b505af4158015612197573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121bb9190614288565b6001600160a01b0316146121e15760405162461bcd60e51b8152600401610432906146c8565b848484428373c7332d9abef755c42b4df9d9db09beef15f8f9fb63f237bab39091858560405160200161221491906145ab565b604051602081830303815290604052805190602001206040518463ffffffff1660e01b8152600401612259939291909283526020830191909152604082015260600190565b60206040518083038186803b15801561227157600080fd5b505af4158015612285573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122a9919061450c565b116122c65760405162461bcd60e51b81526004016104329061463d565b6122d08888613a21565b156122ed5760405162461bcd60e51b815260040161043290614691565b6000341161233d5760405162461bcd60e51b815260206004820152601b60248201527f5374616b655574696c733a206e6f20617661782069732073656e7400000000006044820152606401610432565b60405163f237bab360e01b8152349060009073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab39061237b908d908d906004016147c7565b60206040518083038186803b15801561239357600080fd5b505af41580156123a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123cb919061450c565b60405163f237bab360e01b815290915073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab390612407908d908d906004016147c7565b60206040518083038186803b15801561241f57600080fd5b505af4158015612433573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612457919061450c565b60405163f237bab360e01b815273c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab390612490908e908e90600401614709565b60206040518083038186803b1580156124a857600080fd5b505af41580156124bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124e0919061450c565b111561262c5760405163f237bab360e01b815260009073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab390612522908e908e906004016147c7565b60206040518083038186803b15801561253a57600080fd5b505af415801561254e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612572919061450c565b60405163f237bab360e01b815273c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab3906125ab908f908f90600401614709565b60206040518083038186803b1580156125c357600080fd5b505af41580156125d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125fb919061450c565b6126059190614856565b9050828111156126125750815b61261c818361480b565b91506126288184614856565b9250505b811561270157600061263e8b8b613558565b6001600160a01b03166314a6bf0f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561267657600080fd5b505afa15801561268a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126ae919061450c565b9050670de0b6b3a76400008111156126ec57828111156126cb5750815b6126de8c8c60008d856000600019613784565b506126e98184614856565b92505b82156126ff576126fc838361480b565b91505b505b73c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea4008b8b612727868661480b565b6040518463ffffffff1660e01b8152600401612745939291906147e5565b60006040518083038186803b15801561275d57600080fd5b505af4158015612771573d6000803e3d6000fd5b505060405163f237bab360e01b81526000925073c7332d9abef755c42b4df9d9db09beef15f8f9fb915063f237bab3906127b1908e908e90600401614781565b60206040518083038186803b1580156127c957600080fd5b505af41580156127dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612801919061450c565b9050348111156128845773c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea4008c8c6128313486614856565b6040518463ffffffff1660e01b815260040161284f939291906147a0565b60006040518083038186803b15801561286757600080fd5b505af415801561287b573d6000803e3d6000fd5b505050506128f0565b6040516223bfa960ea1b815273c7332d9abef755c42b4df9d9db09beef15f8f9fb90638efea400906128bf908e908e906000906004016147a0565b60006040518083038186803b1580156128d757600080fd5b505af41580156128eb573d6000803e3d6000fd5b505050505b604080518b8152602081018b9052348183015290517fde3db790d888b38bebb70a5e7060eebb2bc072ab3e5de4c2b3e58bf9d057dc5d9181900360600190a1505050505050505050505050565b604051630143c90b60e71b815282908290339073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e485809061297c9086908690600401614760565b60206040518083038186803b15801561299457600080fd5b505af41580156129a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129cc9190614288565b6001600160a01b0316146129f25760405162461bcd60e51b8152600401610432906146c8565b60408051602081018252600081529051630eee4dd960e41b815273c7332d9abef755c42b4df9d9db09beef15f8f9fb9163eee4dd9091612a3991889188919060040161472d565b60006040518083038186803b158015612a5157600080fd5b505af4158015612a65573d6000803e3d6000fd5b505050507fb65b578bda484b20413a2e121e50adf4c8d77c34c2459a2f658d8a228b8279cb8360405161185791815260200190565b60038801546000906001600160a01b03163314612b035760405162461bcd60e51b815260206004820152602160248201527f5374616b655574696c733a206d73672e73656e646572204e4f54206f7261636c6044820152606560f81b6064820152608401610432565b612b0d8887613a21565b612b595760405162461bcd60e51b815260206004820181905260248201527f5374616b655574696c733a204f7261636c65206973204e4f54206163746976656044820152606401610432565b612b6561070842614856565b871015612bc85760405162461bcd60e51b815260206004820152602b60248201527f5374616b655574696c733a205265706f727465642074696d657374616d70206960448201526a1cc81393d5081d985b1a5960aa1b6064820152608401610432565b600080612bda8b8b8a8a8a8a8a613c92565b60405163f237bab360e01b81529193509150600090839073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab390612c1d908f908e90600401614781565b60206040518083038186803b158015612c3557600080fd5b505af4158015612c49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c6d919061450c565b612c77919061480b565b6040516223bfa960ea1b815290915073c7332d9abef755c42b4df9d9db09beef15f8f9fb90638efea40090612cb4908e908d9086906004016147a0565b60006040518083038186803b158015612ccc57600080fd5b505af4158015612ce0573d6000803e3d6000fd5b505050506000828c73c7332d9abef755c42b4df9d9db09beef15f8f9fb63f237bab390918d6040518363ffffffff1660e01b8152600401612d22929190614709565b60206040518083038186803b158015612d3a57600080fd5b505af4158015612d4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d72919061450c565b612d7c919061480b565b6040516223bfa960ea1b8152600481018e9052602481018c90526c756e636c61696d65644665657360981b60448201526064810182905290915073c7332d9abef755c42b4df9d9db09beef15f8f9fb90638efea4009060840160006040518083038186803b158015612ded57600080fd5b505af4158015612e01573d6000803e3d6000fd5b50505050612e168d546001600160a01b031690565b6001600160a01b031663bd85b0398b6040518263ffffffff1660e01b8152600401612e4391815260200190565b60206040518083038186803b158015612e5b57600080fd5b505afa158015612e6f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e93919061450c565b670de0b6b3a7640000828e73c7332d9abef755c42b4df9d9db09beef15f8f9fb63f237bab390918f6040518363ffffffff1660e01b8152600401612ed89291906147c7565b60206040518083038186803b158015612ef057600080fd5b505af4158015612f04573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f28919061450c565b612f32908661480b565b612f3c9190614856565b612f469190614837565b612f509190614823565b9450612f5e8d8d8c886140ab565b612f698d868c613b95565b6040516223bfa960ea1b8152600481018d9052602481018b90527406f7261636c6555706461746554696d655374616d7605c1b604482015242606482015273c7332d9abef755c42b4df9d9db09beef15f8f9fb90638efea4009060840160006040518083038186803b158015612fde57600080fd5b505af4158015612ff2573d6000803e3d6000fd5b5050604080518d81526020810189905290810185905260608101869052608081018e90527fd6830e63bb637542d836b7e0c83b3f7f93ec3a7aa07ecbdd5e4be539ca8baded925060a001905060405180910390a15050505098975050505050505050565b600983015460405163f237bab360e01b815260048101849052602481018390526266656560e81b60448201526000919073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab39060640160206040518083038186803b1580156130bd57600080fd5b505af41580156130d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130f5919061450c565b116131955760405163f237bab360e01b815260048101849052602481018390526266656560e81b604482015273c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab39060640160206040518083038186803b15801561315857600080fd5b505af415801561316c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613190919061450c565b61319b565b83600901545b949350505050565b600080826040516020016131d09181526d616363756d756c6174656446656560901b6020820152602e0190565b60408051808303601f1901815290829052805160209091012063f237bab360e01b8252600482018790526024820186905260448201819052915073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab39060640160206040518083038186803b15801561324157600080fd5b505af4158015613255573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613279919061450c565b9150935093915050565b604051630143c90b60e71b815260009084908490339073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e48580906132c59086908690600401614760565b60206040518083038186803b1580156132dd57600080fd5b505af41580156132f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133159190614288565b6001600160a01b03161461333b5760405162461bcd60e51b8152600401610432906146c8565b60405163f237bab360e01b815260048101879052602481018690526d30b1ba34bb32a7b832b930ba37b960911b6044820152849073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab39060640160206040518083038186803b1580156133a657600080fd5b505af41580156133ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133de919061450c565b141561346c576040516223bfa960ea1b815260048101879052602481018690526d30b1ba34bb32a7b832b930ba37b960911b60448201526000606482015273c7332d9abef755c42b4df9d9db09beef15f8f9fb90638efea4009060840160006040518083038186803b15801561345357600080fd5b505af4158015613467573d6000803e3d6000fd5b505050505b8573c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea4009091878760405160200161349b91906145ab565b604051602081830303815290604052805190602001206213c680426134c0919061480b565b6040516001600160e01b031960e087901b168152600481019490945260248401929092526044830152606482015260840160006040518083038186803b15801561350957600080fd5b505af415801561351d573d6000803e3d6000fd5b505060408051888152602081018890527f01d08061ca1d76ec162ee0ace672e4f6b555823b72979c7881e786cc68ac3f779350019050612069565b604051630143c90b60e71b815260048101839052602481018290526d1dda5d1a191c985dd85b141bdbdb60921b604482015260009073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e4858090606401611410565b604051630143c90b60e71b815283908390339073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063a1e48580906135f09086908690600401614760565b60206040518083038186803b15801561360857600080fd5b505af415801561361c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136409190614288565b6001600160a01b0316146136665760405162461bcd60e51b8152600401610432906146c8565b85600901548311156136c65760405162461bcd60e51b8152602060048201526024808201527f5374616b655574696c733a204d41585f4d41494e5441494e45525f4645452045604482015263292927a960e11b6064820152608401610432565b6040516223bfa960ea1b815260048101869052602481018590526266656560e81b60448201526064810184905273c7332d9abef755c42b4df9d9db09beef15f8f9fb90638efea4009060840160006040518083038186803b15801561372a57600080fd5b505af415801561373e573d6000803e3d6000fd5b505060408051878152602081018790527f81a262d98ca887595ab153e1384407a02b7a2aaf612822e067f9dd6613a84ce2935001905060405180910390a1505050505050565b60006137908786613558565b6040516348b4aac360e11b815260006004820152600160248201526044810186905260648101859052608481018490526001600160a01b039190911690639169558690869060a4016020604051808303818588803b1580156137f157600080fd5b505af1158015613805573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061382a919061450c565b90506001600160a01b0386166138b35787546001600160a01b0316604051637a94c56560e11b815230600482015260248101879052604481018390526001600160a01b03919091169063f5298aca90606401600060405180830381600087803b15801561389657600080fd5b505af11580156138aa573d6000803e3d6000fd5b5050505061393e565b87546001600160a01b0316604051637921219560e11b81523060048201526001600160a01b038881166024830152604482018890526064820184905260a06084830152600060a4830152919091169063f242432a9060c401600060405180830381600087803b15801561392557600080fd5b505af1158015613939573d6000803e3d6000fd5b505050505b979650505050505050565b600082116139a45760405162461bcd60e51b815260206004820152602260248201527f5374616b655574696c733a205f6d696e742069642073686f756c64206265203e604482015261020360f41b6064820152608401610432565b60405163731133e960e01b81526001600160a01b0384811660048301526024820184905260448201839052608060648301526000608483015285169063731133e99060a401600060405180830381600087803b158015613a0357600080fd5b505af1158015613a17573d6000803e3d6000fd5b5050505050505050565b6000610708613a3362015180426148b8565b111580156114605750613a4861070842614856565b60405163f237bab360e01b815260048101859052602481018490527406f7261636c6555706461746554696d655374616d7605c1b604482015273c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab39060640160206040518083038186803b158015613ab857600080fd5b505af4158015613acc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613af0919061450c565b109392505050565b6000604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81528260601b60148201526e5af43d82803e903d91602b57fd5bf360881b60288201526037816000f09150506001600160a01b038116613b905760405162461bcd60e51b8152602060048201526016602482015275115490cc4c4d8dce8818dc99585d194819985a5b195960521b6044820152606401610432565b919050565b60008111613be55760405162461bcd60e51b815260206004820152601c60248201527f5374616b655574696c733a2069642073686f756c64206265203e2030000000006044820152606401610432565b82546001600160a01b03166040516322af599760e01b815260048101849052602481018390526001600160a01b0391909116906322af599790604401600060405180830381600087803b158015613c3b57600080fd5b505af1158015613c4f573d6000803e3d6000fd5b505060408051848152602081018690527f8aa4fa52648a6d15edce8a179c792c86f3719d0cc3c572cf90f91948f0f2cb68935001905060405180910390a1505050565b600080848314613cf45760405162461bcd60e51b815260206004820152602760248201527f5374616b655574696c733a204172726179206c656e6774687320646f65736e276044820152660e840dac2e8c6d60cb1b6064820152608401610432565b60005b85811015613fc55787878783818110613d1257613d126148f8565b9050602002013514613f8d57613d2b6201518042614856565b73c7332d9abef755c42b4df9d9db09beef15f8f9fb63f237bab38b8b8b8b87818110613d5957613d596148f8565b90506020020135604051602001613d7091906145ab565b604051602081830303815290604052805190602001206040518463ffffffff1660e01b8152600401613db5939291909283526020830191909152604082015260600190565b60206040518083038186803b158015613dcd57600080fd5b505af4158015613de1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e05919061450c565b11613e6a5760405162461bcd60e51b815260206004820152602f60248201527f5374616b655574696c733a205f6f7049642061637469766174696f6e4578706960448201526e1c985d1a5bdb881a185cc81c185cdd608a1b6064820152608401610432565b6000613e8f8b8b8a8a86818110613e8357613e836148f8565b90506020020135613056565b9050600080613eb78c8c8c8c88818110613eab57613eab6148f8565b905060200201356131a3565b9150915060008d60070154898987818110613ed457613ed46148f8565b9050602002013585613ee69190614837565b613ef09190614823565b905073c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea4008e8e85613f19868961480b565b6040516001600160e01b031960e087901b168152600481019490945260248401929092526044830152606482015260840160006040518083038186803b158015613f6257600080fd5b505af4158015613f76573d6000803e3d6000fd5b505050508086613f86919061480b565b9550505050505b848482818110613f9f57613f9f6148f8565b9050602002013583613fb1919061480b565b925080613fbd8161489d565b915050613cf7565b506000613fd38a8a8a613056565b905060008a600701548483613fe89190614837565b613ff29190614823565b90506000806140028c8c8d6131a3565b9092509050614011838661480b565b945073c7332d9abef755c42b4df9d9db09beef15f8f9fb638efea4008d8d8461403a888861480b565b6040516001600160e01b031960e087901b168152600481019490945260248401929092526044830152606482015260840160006040518083038186803b15801561408357600080fd5b505af4158015614097573d6000803e3d6000fd5b505050505050505097509795505050505050565b60405163f237bab360e01b815260048101849052602481018390527406f7261636c6555706461746554696d655374616d7605c1b6044820152600090620151809073c7332d9abef755c42b4df9d9db09beef15f8f9fb9063f237bab39060640160206040518083038186803b15801561412357600080fd5b505af4158015614137573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061415b919061450c565b6141676107084261480b565b6141719190614856565b61417b9190614823565b905060006141898685611467565b905060008660070154838860080154846141a39190614837565b6141ad9190614837565b6141b79190614823565b6141c1908361480b565b90508084111580156141d35750818410155b6116e85760405162461bcd60e51b815260206004820152601d60248201527f5374616b655574696c733a20707269636520646964204e4f54206d65740000006044820152606401610432565b60008083601f84011261423157600080fd5b50813567ffffffffffffffff81111561424957600080fd5b6020830191508360208260051b850101111561426457600080fd5b9250929050565b60006020828403121561427d57600080fd5b813561146081614924565b60006020828403121561429a57600080fd5b815161146081614924565b6000602082840312156142b757600080fd5b8151801515811461146057600080fd5b6000602082840312156142d957600080fd5b815167ffffffffffffffff808211156142f157600080fd5b818401915084601f83011261430557600080fd5b8151818111156143175761431761490e565b604051601f8201601f19908116603f0116810190838211818310171561433f5761433f61490e565b8160405282815287602084870101111561435857600080fd5b61393e83602083016020880161486d565b6000806040838503121561437c57600080fd5b50508035926020909101359150565b6000806000606084860312156143a057600080fd5b833592506020840135915060408401356143b981614924565b809150509250925092565b6000806000606084860312156143d957600080fd5b505081359360208301359350604090920135919050565b60006020828403121561440257600080fd5b5035919050565b6000806000806080858703121561441f57600080fd5b5050823594602084013594506040840135936060013592509050565b60008060008060008060008060c0898b03121561445757600080fd5b88359750602089013596506040890135955060608901359450608089013567ffffffffffffffff8082111561448b57600080fd5b6144978c838d0161421f565b909650945060a08b01359150808211156144b057600080fd5b506144bd8b828c0161421f565b999c989b5096995094979396929594505050565b600080600080600060a086880312156144e957600080fd5b505083359560208501359550604085013594606081013594506080013592509050565b60006020828403121561451e57600080fd5b5051919050565b6000815180845261453d81602086016020860161486d565b601f01601f19169290920160200192915050565b6000825161456381846020870161486d565b6e16a3b2b7b232902ba8102a37b5b2b760891b920191825250600f01919050565b6000825161459681846020870161486d565b6202d57560ec1b920191825250600301919050565b9081527330b1ba34bb30ba34b7b722bc3834b930ba34b7b760611b602082015260340190565b6001600160a01b03898116825260208201899052610100604083018190526000916145fe8483018b614525565b91508382036060850152614612828a614525565b92508760808501528660a08501528560c085015280851660e085015250509998505050505050505050565b60208082526034908201527f5374616b655574696c733a206f70657261746f7249642061637469766174696f6040820152731b915e1c1a5c985d1a5bdb881a185cc81c185cdd60621b606082015260800190565b6020808252601c908201527f5374616b655574696c733a204f7261636c652069732061637469766500000000604082015260600190565b60208082526021908201527f5374616b655574696c733a2073656e646572206e6f74206d61696e7461696e656040820152603960f91b606082015260800190565b91825260208201526c756e636c61696d65644665657360981b604082015260600190565b8381528260208201526a1cdd185ad954185d5cd95960aa1b60408201526080606082015260006106fe6080830184614525565b91825260208201526936b0b4b73a30b4b732b960b11b604082015260600190565b9182526020820152677042616c616e636560c01b604082015260600190565b9283526020830191909152677042616c616e636560c01b6040830152606082015260800190565b918252602082015266737572706c757360c81b604082015260600190565b928352602083019190915266737572706c757360c81b6040830152606082015260800190565b6000821982111561481e5761481e6148cc565b500190565b600082614832576148326148e2565b500490565b6000816000190483118215151615614851576148516148cc565b500290565b600082821015614868576148686148cc565b500390565b60005b83811015614888578181015183820152602001614870565b83811115614897576000848401525b50505050565b60006000198214156148b1576148b16148cc565b5060010190565b6000826148c7576148c76148e2565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461493957600080fd5b5056fea2646970667358221220db399a718cebf5609cc9db0f2b257cb28a3d5c5bf6fd32db5fabef5826217a4b64736f6c63430008070033

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.