Contract 0xc1480b1c3f6a2a64aa6cc9a38f958530e283e372

 

Contract Overview

Balance:
0 FTM

FTM Value:
$0.00

Token:
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x3912535dc623f8ec3a0b5ac682f5ada7edcc7487c07d8f574d8288d26a212742Stake For Debts505137512022-11-06 0:21:2529 days 10 mins ago0xfb50d336124f7189ecacb0144e8977240e8a00f3 IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.029377982404
0x68cc6de105c4af2abd709cdeb15d6ddeadf85a1f6d39e6d6e5cd74334f09f5c1Stake For Debts501971722022-10-29 1:22:4636 days 23 hrs ago0xfb50d336124f7189ecacb0144e8977240e8a00f3 IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.0009140202
0x6955daa4601dc3b5aad97babed2f10e65ccc48f039fbe0c36eba50b2d94556b1Stake For Deposi...478533742022-09-27 8:55:3968 days 15 hrs ago0xd2ab081c2c880a18bd0315f13aa76a27ffa63439 IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.000231565
0x974a8c5d68af3c62fdc5a2632ce7d7969dd322440cc578b4d7bb17c25cd0af03Stake For Debts478276912022-09-27 0:42:5068 days 23 hrs ago0xfb50d336124f7189ecacb0144e8977240e8a00f3 IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.000160737152
0x91872c197d76fc5442f8ddd5b5d8bacd6f16ff022c049a98dd056835eb656c1fStake For Debts478125182022-09-26 19:54:4869 days 4 hrs ago0xfb50d336124f7189ecacb0144e8977240e8a00f3 IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.000156725
0x5ef179c5e629714e51e701951a19533f0e403413c8d96453462936a45b5eba55Grant Role478053592022-09-26 17:37:0869 days 6 hrs agoKanpeki: Deployer IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.000157200055
0x380ded6c867920ce0dab3942e80f5bd40a9186d597020950ab6dafb90a6378abRevoke Role478052942022-09-26 17:35:5269 days 6 hrs agoKanpeki: Deployer IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.000075825555
0x805a314ab05754373164f9e059de130c6bacbf910c014986b31df68bd0fd1674Stake For Debts476516802022-09-24 17:31:1171 days 7 hrs ago0xfb50d336124f7189ecacb0144e8977240e8a00f3 IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.00017470599
0x5b6d8c3fdf766b6f0d3b916137e38b40bd4cba65d9f314b31a339310f957dc6cStake For Debts472101952022-09-18 19:23:4177 days 5 hrs ago0xfb50d336124f7189ecacb0144e8977240e8a00f3 IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.00044015288
0xd960f61200e6b21b885c3bed02dc433ef95245f781508e7960e9e34d40e89b28Grant Role471565432022-09-18 0:55:4077 days 23 hrs agoKanpeki: Deployer IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.000112473511
0xa64a87c27ba7f6c32d118198b59993e6582b5ae5a12e8756c2b5c0ef6861a6fcGrant Role471565352022-09-18 0:55:3277 days 23 hrs agoKanpeki: Deployer IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.000112453454
0x70c380618f1f27a2cba6ace9342ab7151f295cf843f9bed209bae6f035ffd6e2Grant Role471565282022-09-18 0:55:2477 days 23 hrs agoKanpeki: Deployer IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.00011238275
0x825923ad5b699a354d5b0f38337790f48ef6cd21045b37a45b9c6e981905d3f5Update Config470848212022-09-17 0:47:5678 days 23 hrs agoKanpeki: Deployer IN  0xc1480b1c3f6a2a64aa6cc9a38f958530e283e3720 FTM0.000179494474
0x951ef5541dbc60be28d00498f279fd4699a62c27ded741b35046500563effb9c0x60806040470847862022-09-17 0:46:5878 days 23 hrs agoKanpeki: Deployer IN  Create: StakingManager0 FTM0.00462153118
[ Download CSV Export 
Latest 1 internal transaction
Parent Txn Hash Block From To Value
0x951ef5541dbc60be28d00498f279fd4699a62c27ded741b35046500563effb9c470847862022-09-17 0:46:5878 days 23 hrs ago Kanpeki: Deployer  Contract Creation0 FTM
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
StakingManager

Compiler Version
v0.8.6+commit.11564f7e

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 21 : StakingManager.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.6;

import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { AccessControlEnumerable } from "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { IKAE } from "../interfaces/IKAE.sol";
import { IContractRegistry } from "../interfaces/IContractRegistry.sol";
import { IOracle } from "../interfaces/IOracle.sol";
import { Deposit, IDepositManager } from "../interfaces/IDepositManager.sol";
import { IStakingManager } from "../interfaces/IStakingManager.sol";


contract StakingManager is IStakingManager, AccessControlEnumerable, ReentrancyGuard
{
  using SafeERC20 for IERC20;


  IContractRegistry private constant _REGISTRY = IContractRegistry(0x06Eeb1B35361687f10909902AD4704AC7d09e0E7);
  address private constant _KAE = 0x65Def5029A0e7591e46B38742bFEdd1Fb7b24436;

  bytes32 private constant _FOR_DEPOSITS = keccak256("FOR_DEPOSITS");
  bytes32 private constant _FOR_DEBTS = keccak256("FOR_DEBTS");

  bytes32 public constant STAKER_ROLE = keccak256("STAKER_ROLE");

  uint256 private constant _DECIMALS = 1e18;
  uint256 private constant _BASIS_POINT = 10000;


  struct Config
  {
    bool stakable;
    uint112 minForDeposits;
    uint112 minForDebts;
    uint256 lastPriceInUSD;
  }

  struct Stake
  {
    uint32 unstakableTimestamp;
    uint112 expected;
    uint112 amount;
  }

  Config private _config;

  mapping(address => mapping(bytes32 => Stake)) private _stake;


  event NewConfig(uint256 price, uint256 minForDeposits, uint256 minForDebts, bool stakable);

  event NewStake(address indexed account, bytes32 indexed stakeFor, uint256 amount);
  event Unstake(address indexed account, bytes32 indexed stakeFor, uint256 amount);


  constructor ()
  {
    _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);

    _setRoleAdmin(STAKER_ROLE, DEFAULT_ADMIN_ROLE);
    _setupRole(STAKER_ROLE, msg.sender);
  }

  function _isSTAKER () private view
  {
    require(hasRole(STAKER_ROLE, msg.sender), "!staker");
  }

  function updateConfig (Config calldata config) external
  {
    _isSTAKER();

    require(config.lastPriceInUSD > 0, "!valid price");
    require(config.minForDeposits > 0 && config.minForDebts > 0 && config.minForDeposits < type(uint112).max && config.minForDebts < type(uint112).max, "!valid amt");


    _config = config;


    emit NewConfig(config.lastPriceInUSD, config.minForDeposits, config.minForDebts, config.stakable);
  }

  function getConfig () public view returns (Config memory)
  {
    return _config;
  }


  function _calcPercentOf (uint256 amount, uint256 percent) private pure returns (uint256)
  {
    return (amount * percent) / _BASIS_POINT;
  }


  function _isStaking (address account, bytes32 stakeFor) private view returns (bool)
  {
    return _stake[account][stakeFor].amount > 0;
  }

  function isStakingForDeposits (address account) external view override returns (bool)
  {
    return _isStaking(account, _FOR_DEPOSITS);
  }

  function isStakingForDebts (address account) external view override returns (bool)
  {
    return _isStaking(account, _FOR_DEBTS);
  }

  function isDiscountedForDeposits (address account) external view override returns (bool)
  {
    (uint256 amount, uint256 expected) = (_stake[account][_FOR_DEPOSITS].amount, _stake[account][_FOR_DEPOSITS].expected);


    return amount >= _config.minForDeposits && amount >= expected;
  }

  function isDiscountedForDebts (address account) external view override returns (bool)
  {
    (uint256 amount, uint256 expected) = (_stake[account][_FOR_DEBTS].amount, _stake[account][_FOR_DEBTS].expected);


    return amount >= _config.minForDebts && amount >= expected;
  }

  function getStakesOf (address account) external view returns (Stake memory, Stake memory)
  {
    return (_stake[account][_FOR_DEPOSITS], _stake[account][_FOR_DEBTS]);
  }


  function calcStake (uint256 amountInUSD, uint256 stakeRate) public view returns (uint256)
  {
    return (_calcPercentOf(amountInUSD, stakeRate) * _DECIMALS) / _config.lastPriceInUSD;
  }


  function _initStake (uint256 amount, bytes32 stakeFor) private
  {
    require(amount > 0 && amount < type(uint112).max, "!valid amt");


    uint256 min = stakeFor == _FOR_DEPOSITS ? (_config.minForDeposits + _depositsCumulativeStake(msg.sender)) : _config.minForDebts;

    uint256 total = min + amount;


    _stake[msg.sender][stakeFor] = Stake
    ({
      expected: uint112(min),
      amount: uint112(total),
      unstakableTimestamp: uint32(block.timestamp + 60 days)
    });


    IERC20(_KAE).safeTransferFrom(msg.sender, address(this), total);


    emit NewStake(msg.sender, stakeFor, total);
  }

  function _addStake (uint256 amount, bytes32 stakeFor) private
  {
    require(amount > 0 && amount < type(uint112).max, "!valid amt");


    _stake[msg.sender][stakeFor].amount += uint112(amount);
    _stake[msg.sender][stakeFor].unstakableTimestamp = uint32(block.timestamp + 60 days);


    IERC20(_KAE).safeTransferFrom(msg.sender, address(this), amount);


    emit NewStake(msg.sender, stakeFor, amount);
  }


  function _canStake () private view
  {
    require(_config.stakable, "!stakable");
  }


  function _calcDepositsRate (uint256 interestRate) private pure returns (uint256)
  {
    return interestRate > 300 ? interestRate - 200 : 100;
  }

  function _depositsCumulativeStake (address account) private view returns (uint256)
  {
    IDepositManager manager = IDepositManager(_REGISTRY.depositManager());
    address[] memory tokens = manager.getDepositedTokensOf(account);

    uint256 total;


    if (tokens.length > 0)
    {
      IOracle oracle = IOracle(_REGISTRY.oracle());


      for (uint256 i; i < tokens.length; i++)
      {
        address token = tokens[i];
        Deposit memory deposit = manager.getDeposit(account, token);

        total += calcStake(oracle.convertToUSD(token, deposit.amount), _calcDepositsRate(deposit.weightedAvgInterestRate));
      }
    }


    require(total < type(uint112).max, "!valid cmm");


    return total;
  }

  function depositsCumulativeStake (address account) public view returns (uint256)
  {
    return _depositsCumulativeStake(account);
  }

  function _isValidForDeposits (uint256 depositInUSD, uint256 interestRate) private view
  {
    _canStake();
    require(depositInUSD > 0 && depositInUSD < type(uint128).max && interestRate >= 200 && interestRate <= 1000, "!valid amt");
  }

  function stakeForDeposits (uint256 depositInUSD, uint256 interestRate) external nonReentrant
  {
    _isValidForDeposits(depositInUSD, interestRate);


    if (_isStaking(msg.sender, _FOR_DEPOSITS))
    {
      _addStake(calcStake(depositInUSD, _calcDepositsRate(interestRate)), _FOR_DEPOSITS);
    }
    else
    {
      _initStake(calcStake(depositInUSD, _calcDepositsRate(interestRate)), _FOR_DEPOSITS);
    }
  }


  function _isValidForDebts (uint256 debtInUSD) private view
  {
    _canStake();
    require(debtInUSD > 0 && debtInUSD < type(uint128).max, "!valid amt");
  }

  function stakeForDebts (uint256 debtInUSD) external nonReentrant
  {
    _isValidForDebts(debtInUSD);


    if (_isStaking(msg.sender, _FOR_DEBTS))
    {
      _addStake(calcStake(debtInUSD, 100), _FOR_DEBTS);
    }
    else
    {
      _initStake(calcStake(debtInUSD, 100), _FOR_DEBTS);
    }
  }


  function _unstake (bytes32 stakeFor) private
  {
    require(_isStaking(msg.sender, stakeFor), "!staking");


    Stake memory stake = _stake[msg.sender][stakeFor];

    if (_config.stakable)
    {
      require(stake.unstakableTimestamp > 0 && block.timestamp > stake.unstakableTimestamp, "using");


      if (stakeFor == _FOR_DEPOSITS)
      {
        require(_depositsCumulativeStake(msg.sender) == 0, "active deposits");
      }
    }


    _stake[msg.sender][stakeFor].amount = 0;
    _stake[msg.sender][stakeFor].expected = 0;
    _stake[msg.sender][stakeFor].unstakableTimestamp = 0;


    IERC20(_KAE).safeTransfer(msg.sender, stake.amount);


    emit Unstake(msg.sender, stakeFor, stake.amount);
  }

  function unstakeForDeposits () external nonReentrant
  {
    _unstake(_FOR_DEPOSITS);
  }

  function unstakeForDebts () external nonReentrant
  {
    _unstake(_FOR_DEBTS);
  }



  function _increase (address account, uint256 amountInUSD, uint256 stakeRate, bytes32 stakeFor) private
  {
    uint256 expected = Math.max(stakeFor == _FOR_DEPOSITS ? _config.minForDeposits : _config.minForDebts, _stake[account][stakeFor].expected) + calcStake(amountInUSD, stakeRate);

    require(expected > 0 && expected < type(uint112).max, "!valid expected");


    _stake[account][stakeFor].expected = uint112(expected);
  }

  function increaseExpectedForDeposits (address depositor, uint256 depositInUSD, uint256 interestRate) external override
  {
    _isSTAKER();


    if (_isStaking(depositor, _FOR_DEPOSITS))
    {
      _increase(depositor, depositInUSD, _calcDepositsRate(interestRate), _FOR_DEPOSITS);

      _stake[depositor][_FOR_DEPOSITS].unstakableTimestamp = uint32(block.timestamp + 90 days);
    }
  }

  function increaseExpectedForDebts (address borrower, uint256 debtInUSD, uint256 dueTimestamp) external override
  {
    _isSTAKER();


    if (_isStaking(borrower, _FOR_DEBTS))
    {
      _increase(borrower, debtInUSD, 100, _FOR_DEBTS);


      if ((dueTimestamp + 60 days) > _stake[borrower][_FOR_DEBTS].unstakableTimestamp)
      {
        _stake[borrower][_FOR_DEBTS].unstakableTimestamp = uint32(dueTimestamp + 60 days);
      }
    }
  }


  function _decrease (address account, address token, uint256 amount, uint256 stakeRate, bytes32 stakeFor) private
  {
    uint256 decrement = calcStake(IOracle(_REGISTRY.oracle()).convertToUSD(token, amount), stakeRate);

    uint256 min = _calcPercentOf(stakeFor == _FOR_DEPOSITS ? _config.minForDeposits : _config.minForDebts, 10100);

    uint256 expected = decrement > _stake[account][stakeFor].expected ? min : Math.max(min, _stake[account][stakeFor].expected - decrement);

    require(expected > 0 && expected < type(uint112).max, "!valid expected");


    _stake[account][stakeFor].expected = uint112(expected);
  }

  function decreaseExpectedForDeposits (address depositor, address depositToken, uint256 deposit, uint256 interestRate) external override
  {
    _isSTAKER();


    if (_isStaking(depositor, _FOR_DEPOSITS))
    {
      _decrease(depositor, depositToken, deposit, _calcDepositsRate(interestRate), _FOR_DEPOSITS);
    }
  }

  function decreaseExpectedForDebts (address borrower, address debtToken, uint256 debt) external override
  {
    _isSTAKER();


    if (_isStaking(borrower, _FOR_DEBTS))
    {
      _decrease(borrower, debtToken, debt, 100, _FOR_DEBTS);
    }
  }
}

File 2 of 21 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. It the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`.
        // We also know that `k`, the position of the most significant bit, is such that `msb(a) = 2**k`.
        // This gives `2**k < a <= 2**(k+1)` → `2**(k/2) <= sqrt(a) < 2 ** (k/2+1)`.
        // Using an algorithm similar to the msb conmputation, we are able to compute `result = 2**(k/2)` which is a
        // good first aproximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1;
        uint256 x = a;
        if (x >> 128 > 0) {
            x >>= 128;
            result <<= 64;
        }
        if (x >> 64 > 0) {
            x >>= 64;
            result <<= 32;
        }
        if (x >> 32 > 0) {
            x >>= 32;
            result <<= 16;
        }
        if (x >> 16 > 0) {
            x >>= 16;
            result <<= 8;
        }
        if (x >> 8 > 0) {
            x >>= 8;
            result <<= 4;
        }
        if (x >> 4 > 0) {
            x >>= 4;
            result <<= 2;
        }
        if (x >> 2 > 0) {
            result <<= 1;
        }

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        uint256 result = sqrt(a);
        if (rounding == Rounding.Up && result * result < a) {
            result += 1;
        }
        return result;
    }
}

File 3 of 21 : AccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlEnumerable.sol";
import "./AccessControl.sol";
import "../utils/structs/EnumerableSet.sol";

/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
    using EnumerableSet for EnumerableSet.AddressSet;

    mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
        return _roleMembers[role].at(index);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
        return _roleMembers[role].length();
    }

    /**
     * @dev Overload {_grantRole} to track enumerable memberships
     */
    function _grantRole(bytes32 role, address account) internal virtual override {
        super._grantRole(role, account);
        _roleMembers[role].add(account);
    }

    /**
     * @dev Overload {_revokeRole} to track enumerable memberships
     */
    function _revokeRole(bytes32 role, address account) internal virtual override {
        super._revokeRole(role, account);
        _roleMembers[role].remove(account);
    }
}

File 4 of 21 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

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

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

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

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

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

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

File 7 of 21 : IKAE.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.6;


interface IKAE
{
  function mint (address to, uint256 amount) external;

  function burn (uint256 amount) external;
}

File 8 of 21 : IContractRegistry.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.6;


struct Contracts
{
  address oracle;
  address tokenRegistry;
  address coordinator;
  address stakingManager;
  address feeManager;
  address collateralizationManager;
  address rewardManager;
}


interface IContractRegistry
{
  function getContract (bytes32 key) external view returns (address);


  function borrowContracts () external view returns (Contracts memory);


  function oracle () external view returns (address);

  function tokenRegistry () external view returns (address);

  function vault () external view returns (address);

  function coordinator () external view returns (address);

  function depositManager () external view returns (address);

  function borrowManager () external view returns (address);

  function stakingManager () external view returns (address);

  function feeManager () external view returns (address);

  function collateralizationManager () external view returns (address);

  function rewardManager () external view returns (address);
}

File 9 of 21 : IOracle.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.6;


interface IOracle
{
  function getConversionRate (address fromToken, address toToken) external view returns (uint256);

  function convertFromUSD (address toToken, uint256 amount) external view returns (uint256);

  function convertToUSD (address fromToken, uint256 amount) external view returns (uint256);

  function convert (address fromToken, address toToken, uint256 amount) external view returns (uint256);
}

File 10 of 21 : IDepositManager.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.6;


struct Deposit
{
  uint16 weightedAvgInterestRate;
  uint32 redepositableTimestamp;
  uint32 withdrawableTimestamp;
  uint128 amount;
  uint256 vaultCumulativeInterestAtLastDeposit;
}

interface IDepositManager
{
  function getDeposit (address depositor, address token) external view returns (Deposit memory);

  function getDepositedTokensOf (address depositor) external view returns (address[] memory);
}

File 11 of 21 : IStakingManager.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.6;


interface IStakingManager
{
  function isStakingForDeposits (address account) external view returns (bool);

  function isDiscountedForDeposits (address account) external view returns (bool);


  function isStakingForDebts (address account) external view returns (bool);

  function isDiscountedForDebts (address account) external view returns (bool);


  function increaseExpectedForDeposits (address depositor, uint256 depositInUSD, uint256 interestRate) external;

  function decreaseExpectedForDeposits (address depositor, address depositToken, uint256 deposit, uint256 interestRate) external;


  function increaseExpectedForDebts (address borrower, uint256 debtInUSD, uint256 dueTimestamp) external;

  function decreaseExpectedForDebts (address borrower, address debtToken, uint256 debt) external;
}

File 12 of 21 : IAccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerable is IAccessControl {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

File 13 of 21 : AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(uint160(account), 20),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 14 of 21 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 *  Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
 *  See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 *  In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 15 of 21 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

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

pragma solidity ^0.8.0;

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

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

File 17 of 21 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

File 18 of 21 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

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

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

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

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minForDeposits","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minForDebts","type":"uint256"},{"indexed":false,"internalType":"bool","name":"stakable","type":"bool"}],"name":"NewConfig","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"bytes32","name":"stakeFor","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"NewStake","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"bytes32","name":"stakeFor","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unstake","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STAKER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountInUSD","type":"uint256"},{"internalType":"uint256","name":"stakeRate","type":"uint256"}],"name":"calcStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"debtToken","type":"address"},{"internalType":"uint256","name":"debt","type":"uint256"}],"name":"decreaseExpectedForDebts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"depositor","type":"address"},{"internalType":"address","name":"depositToken","type":"address"},{"internalType":"uint256","name":"deposit","type":"uint256"},{"internalType":"uint256","name":"interestRate","type":"uint256"}],"name":"decreaseExpectedForDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"depositsCumulativeStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getConfig","outputs":[{"components":[{"internalType":"bool","name":"stakable","type":"bool"},{"internalType":"uint112","name":"minForDeposits","type":"uint112"},{"internalType":"uint112","name":"minForDebts","type":"uint112"},{"internalType":"uint256","name":"lastPriceInUSD","type":"uint256"}],"internalType":"struct StakingManager.Config","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getStakesOf","outputs":[{"components":[{"internalType":"uint32","name":"unstakableTimestamp","type":"uint32"},{"internalType":"uint112","name":"expected","type":"uint112"},{"internalType":"uint112","name":"amount","type":"uint112"}],"internalType":"struct StakingManager.Stake","name":"","type":"tuple"},{"components":[{"internalType":"uint32","name":"unstakableTimestamp","type":"uint32"},{"internalType":"uint112","name":"expected","type":"uint112"},{"internalType":"uint112","name":"amount","type":"uint112"}],"internalType":"struct StakingManager.Stake","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"debtInUSD","type":"uint256"},{"internalType":"uint256","name":"dueTimestamp","type":"uint256"}],"name":"increaseExpectedForDebts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"depositor","type":"address"},{"internalType":"uint256","name":"depositInUSD","type":"uint256"},{"internalType":"uint256","name":"interestRate","type":"uint256"}],"name":"increaseExpectedForDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isDiscountedForDebts","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isDiscountedForDeposits","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isStakingForDebts","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isStakingForDeposits","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"debtInUSD","type":"uint256"}],"name":"stakeForDebts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"depositInUSD","type":"uint256"},{"internalType":"uint256","name":"interestRate","type":"uint256"}],"name":"stakeForDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unstakeForDebts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unstakeForDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"stakable","type":"bool"},{"internalType":"uint112","name":"minForDeposits","type":"uint112"},{"internalType":"uint112","name":"minForDebts","type":"uint112"},{"internalType":"uint256","name":"lastPriceInUSD","type":"uint256"}],"internalType":"struct StakingManager.Config","name":"config","type":"tuple"}],"name":"updateConfig","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b5060016002556200002460003362000061565b6200004060008051602062002cba833981519152600062000071565b6200005b60008051602062002cba8339815191523362000061565b62000211565b6200006d8282620000bc565b5050565b600082815260208190526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b620000d38282620000ff60201b62000d811760201c565b6000828152600160209081526040909120620000fa91839062000e056200019f821b17901c565b505050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166200006d576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200015b3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000620001b6836001600160a01b038416620001bf565b90505b92915050565b60008181526001830160205260408120546200020857508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155620001b9565b506000620001b9565b612a9980620002216000396000f3fe608060405234801561001057600080fd5b50600436106101a85760003560e01c80638cb128fb116100f9578063b5848f3611610097578063d547741f11610071578063d547741f1461043e578063e3a549ad14610451578063fafc08c414610464578063fe31f18b1461055657600080fd5b8063b5848f3614610369578063c3f909d41461037c578063ca15c8731461042b57600080fd5b80639010d07c116100d35780639010d07c1461031057806391d148541461033b57806392be9b841461034e578063a217fddf1461036157600080fd5b80638cb128fb146102d75780638e3a8f74146102ea5780638ea9cbc3146102fd57600080fd5b806336562ebb11610166578063394924761161014057806339492476146102a15780633ad16745146102b457806346eb8f77146102c75780636f8582cf146102cf57600080fd5b806336562ebb1461025457806336568abe146102675780633780b3ed1461027a57600080fd5b80627c3248146101ad57806301ffc9a7146101c2578063248a9ca3146101ea5780632f2ff15d1461021b578063309aa0261461022e5780633545e72614610241575b600080fd5b6101c06101bb366004612314565b610569565b005b6101d56101d036600461252e565b6105af565b60405190151581526020015b60405180910390f35b61020d6101f83660046124c3565b60009081526020819052604090206001015490565b6040519081526020016101e1565b6101c06102293660046124dc565b6105da565b6101d561023c3660046122da565b6105ff565b6101c061024f36600461239b565b610619565b61020d61026236600461250c565b610701565b6101c06102753660046124dc565b610735565b61020d7fb9e206fa2af7ee1331b72ce58b6d938ac810ce9b5cdb65d35ab723fd67badf9e81565b6101c06102af366004612558565b6107b8565b61020d6102c23660046122da565b610953565b6101c061095e565b6101c06109a2565b6101c06102e5366004612355565b6109df565b6101c06102f836600461239b565b610a2d565b6101d561030b3660046122da565b610ad1565b61032361031e36600461250c565b610aeb565b6040516001600160a01b0390911681526020016101e1565b6101d56103493660046124dc565b610b03565b6101c061035c36600461250c565b610b2c565b61020d600081565b6101c06103773660046124c3565b610bcf565b6103e8604080516080810182526000808252602082018190529181018290526060810191909152506040805160808101825260035460ff8116151582526001600160701b03610100820481166020840152600160781b9091041691810191909152600454606082015290565b604080518251151581526020808401516001600160701b0390811691830191909152838301511691810191909152606091820151918101919091526080016101e1565b61020d6104393660046124c3565b610c6c565b6101c061044c3660046124dc565b610c83565b6101d561045f3660046122da565b610ca8565b6105486104723660046122da565b6040805160608082018352600080835260208084018290529284018190528351808301855281815280840182905284018190526001600160a01b0394909416845260058252828420600080516020612a4483398151915285528252828420600080516020612a2483398151915285529383902083518083018552945463ffffffff80821687526001600160701b03600160201b808404821689880152600160901b938490048216898901528751958601885293549182168552928104831694840194909452909204909116918101919091529091565b6040516101e1929190612765565b6101d56105643660046122da565b610d18565b610571610e1a565b61058983600080516020612a24833981519152610e7c565b156105aa576105aa8383836064600080516020612a24833981519152610eb6565b505050565b60006001600160e01b03198216635a05180f60e01b14806105d457506105d48261115b565b92915050565b6000828152602081905260409020600101546105f581611190565b6105aa838361119d565b60006105d482600080516020612a44833981519152610e7c565b610621610e1a565b61063983600080516020612a24833981519152610e7c565b156105aa5761065983836064600080516020612a248339815191526111bf565b6001600160a01b0383166000908152600560209081526040808320600080516020612a24833981519152845290915290205463ffffffff1661069e82624f1a0061282a565b11156105aa576106b181624f1a0061282a565b6001600160a01b0384166000908152600560209081526040808320600080516020612a2483398151915284529091529020805463ffffffff9290921663ffffffff19909216919091179055505050565b600454600090670de0b6b3a764000061071a85856112fc565b6107249190612864565b61072e9190612842565b9392505050565b6001600160a01b03811633146107aa5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b6107b4828261130b565b5050565b6107c0610e1a565b60008160600135116108035760405162461bcd60e51b815260206004820152600c60248201526b2176616c696420707269636560a01b60448201526064016107a1565b60006108156040830160208401612610565b6001600160701b0316118015610843575060006108386060830160408401612610565b6001600160701b0316115b801561086d57506001600160701b036108626040830160208401612610565b6001600160701b0316105b801561089757506001600160701b0361088c6060830160408401612610565b6001600160701b0316105b6108b35760405162461bcd60e51b81526004016107a19061270a565b8060036108c08282612950565b507f852dd1c398fb5f4ce8ed9da7f133c685c67acfe6192ff341a705552790a9d89f905060608201356108f96040840160208501612610565b6109096060850160408601612610565b6109166020860186612489565b60405161094894939291909384526001600160701b039283166020850152911660408301521515606082015260800190565b60405180910390a150565b60006105d48261132d565b6002805414156109805760405162461bcd60e51b81526004016107a19061272e565b6002805561099b600080516020612a2483398151915261168c565b6001600255565b6002805414156109c45760405162461bcd60e51b81526004016107a19061272e565b6002805561099b600080516020612a4483398151915261168c565b6109e7610e1a565b6109ff84600080516020612a44833981519152610e7c565b15610a2757610a27848484610a1385611872565b600080516020612a44833981519152610eb6565b50505050565b610a35610e1a565b610a4d83600080516020612a44833981519152610e7c565b156105aa57610a748383610a6084611872565b600080516020612a448339815191526111bf565b610a81426276a70061282a565b6001600160a01b0384166000908152600560209081526040808320600080516020612a4483398151915284529091529020805463ffffffff9290921663ffffffff19909216919091179055505050565b60006105d482600080516020612a24833981519152610e7c565b600082815260016020526040812061072e908361188f565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600280541415610b4e5760405162461bcd60e51b81526004016107a19061272e565b60028055610b5c828261189b565b610b7433600080516020612a44833981519152610e7c565b15610ba257610b9d610b898361026284611872565b600080516020612a448339815191526118f0565b610bc6565b610bc6610bb28361026284611872565b600080516020612a44833981519152611a19565b50506001600255565b600280541415610bf15760405162461bcd60e51b81526004016107a19061272e565b60028055610bfe81611bc1565b610c1633600080516020612a24833981519152610e7c565b15610c4257610c3d610c29826064610701565b600080516020612a248339815191526118f0565b610c64565b610c64610c50826064610701565b600080516020612a24833981519152611a19565b506001600255565b60008181526001602052604081206105d490611bfb565b600082815260208190526040902060010154610c9e81611190565b6105aa838361130b565b6001600160a01b0381166000908152600560209081526040808320600080516020612a2483398151915284529091528120546003546001600160701b03600160901b8304811692600160201b9004811691600160781b9004168210801590610d105750808210155b949350505050565b6001600160a01b0381166000908152600560209081526040808320600080516020612a4483398151915284529091528120546003546001600160701b03600160901b8304811692600160201b90048116916101009004168210801590610d105750111592915050565b610d8b8282610b03565b6107b4576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055610dc13390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600061072e836001600160a01b038416611c05565b610e447fb9e206fa2af7ee1331b72ce58b6d938ac810ce9b5cdb65d35ab723fd67badf9e33610b03565b610e7a5760405162461bcd60e51b815260206004820152600760248201526610b9ba30b5b2b960c91b60448201526064016107a1565b565b6001600160a01b039190911660009081526005602090815260408083209383529290522054600160901b90046001600160701b0316151590565b6000610fc87306eeb1b35361687f10909902ad4704ac7d09e0e76001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b158015610f0857600080fd5b505afa158015610f1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f4091906122f7565b60405163f08a25ed60e01b81526001600160a01b03888116600483015260248201889052919091169063f08a25ed9060440160206040518083038186803b158015610f8a57600080fd5b505afa158015610f9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fc2919061262d565b84610701565b9050600061101f600080516020612a448339815191528414610ffc57600354600160781b90046001600160701b031661100e565b60035461010090046001600160701b03165b6001600160701b03166127746112fc565b6001600160a01b038816600090815260056020908152604080832087845290915281205491925090600160201b90046001600160701b031683116110ac576001600160a01b03881660009081526005602090815260408083208784529091529020546110a79083906110a2908690600160201b90046001600160701b0316612883565b611c54565b6110ae565b815b90506000811180156110c657506001600160701b0381105b6111045760405162461bcd60e51b815260206004820152600f60248201526e085d985b1a5908195e1c1958dd1959608a1b60448201526064016107a1565b6001600160a01b0390971660009081526005602090815260408083209583529490529290922080546001600160701b03909716600160201b02640100000000600160901b0319909716969096179095555050505050565b60006001600160e01b03198216637965db0b60e01b14806105d457506301ffc9a760e01b6001600160e01b03198316146105d4565b61119a8133611c6b565b50565b6111a78282610d81565b60008281526001602052604090206105aa9082610e05565b60006111cb8484610701565b61124b600080516020612a4483398151915284146111fb57600354600160781b90046001600160701b031661120d565b60035461010090046001600160701b03165b6001600160a01b03881660009081526005602090815260408083208884529091529020546001600160701b0391821691600160201b90910416611c54565b611255919061282a565b905060008111801561126d57506001600160701b0381105b6112ab5760405162461bcd60e51b815260206004820152600f60248201526e085d985b1a5908195e1c1958dd1959608a1b60448201526064016107a1565b6001600160a01b0390941660009081526005602090815260408083209383529290522080546001600160701b03909416600160201b02640100000000600160901b0319909416939093179092555050565b60006127106107248385612864565b6113158282611ccf565b60008281526001602052604090206105aa9082611d34565b6000807306eeb1b35361687f10909902ad4704ac7d09e0e76001600160a01b0316636c7ac9d86040518163ffffffff1660e01b815260040160206040518083038186803b15801561137d57600080fd5b505afa158015611391573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b591906122f7565b604051636618ae6b60e01b81526001600160a01b038581166004830152919250600091831690636618ae6b9060240160006040518083038186803b1580156113fc57600080fd5b505afa158015611410573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261143891908101906123d0565b9050600080825111156116495760007306eeb1b35361687f10909902ad4704ac7d09e0e76001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b15801561149457600080fd5b505afa1580156114a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114cc91906122f7565b905060005b83518110156116465760008482815181106114ee576114ee612924565b602090810291909101015160405163c35082a960e01b81526001600160a01b038a81166004830152808316602483015291925060009188169063c35082a99060440160a06040518083038186803b15801561154857600080fd5b505afa15801561155c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115809190612570565b606081015160405163f08a25ed60e01b81526001600160a01b0385811660048301526001600160801b039092166024820152919250611625919086169063f08a25ed9060440160206040518083038186803b1580156115de57600080fd5b505afa1580156115f2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611616919061262d565b82516102629061ffff16611872565b61162f908661282a565b94505050808061163e906128dd565b9150506114d1565b50505b6001600160701b038110610d105760405162461bcd60e51b815260206004820152600a6024820152692176616c696420636d6d60b01b60448201526064016107a1565b6116963382610e7c565b6116cd5760405162461bcd60e51b8152602060048201526008602482015267217374616b696e6760c01b60448201526064016107a1565b3360009081526005602090815260408083208484528252918290208251606081018452905463ffffffff811682526001600160701b03600160201b8204811693830193909352600160901b90049091169181019190915260035460ff16156117dd57805163ffffffff161580159061174b5750805163ffffffff1642115b61177f5760405162461bcd60e51b81526020600482015260056024820152647573696e6760d81b60448201526064016107a1565b600080516020612a448339815191528214156117dd5761179e3361132d565b156117dd5760405162461bcd60e51b815260206004820152600f60248201526e616374697665206465706f7369747360881b60448201526064016107a1565b33600081815260056020908152604080832086845290915280822091909155820151611827917365def5029a0e7591e46b38742bfedd1fb7b24436916001600160701b0316611d49565b60408082015190516001600160701b039091168152829033907f4dc55b1ec1ede2cd6cfee754975518e6e491e1d45316abf15c57fecc313c027a906020015b60405180910390a35050565b600061012c82116118845760646105d4565b6105d460c883612883565b600061072e8383611dac565b6118a3611dd6565b6000821180156118b957506001600160801b0382105b80156118c6575060c88110155b80156118d457506103e88111155b6107b45760405162461bcd60e51b81526004016107a19061270a565b60008211801561190657506001600160701b0382105b6119225760405162461bcd60e51b81526004016107a19061270a565b3360009081526005602090815260408083208484529091529020805483919060129061195f908490600160901b90046001600160701b03166127ff565b92506101000a8154816001600160701b0302191690836001600160701b0316021790555042624f1a00611992919061282a565b3360008181526005602090815260408083208684529091529020805463ffffffff191663ffffffff9384161790556119e5917365def5029a0e7591e46b38742bfedd1fb7b24436919030908690611e1416565b604051828152819033907fa35a86a0486fd271bc61194f3c97aee497b7df5dc6e092688e30b5534763bbc090602001611866565b600082118015611a2f57506001600160701b0382105b611a4b5760405162461bcd60e51b81526004016107a19061270a565b6000600080516020612a448339815191528214611a7a57600354600160781b90046001600160701b0316611a9e565b611a833361132d565b600354611a9e919061010090046001600160701b031661282a565b90506000611aac848361282a565b9050604051806060016040528042624f1a00611ac8919061282a565b63ffffffff90811682526001600160701b03808616602080850191909152858216604094850152336000818152600583528581208a82528352859020865181549388015197909601518416600160901b0271ffffffffffffffffffffffffffffffffffff97909416600160201b0271ffffffffffffffffffffffffffffffffffff1990931695851695909517919091179490941617909155611b84917365def5029a0e7591e46b38742bfedd1fb7b244369130908590611e1416565b604051818152839033907fa35a86a0486fd271bc61194f3c97aee497b7df5dc6e092688e30b5534763bbc09060200160405180910390a350505050565b611bc9611dd6565b600081118015611bdf57506001600160801b0381105b61119a5760405162461bcd60e51b81526004016107a19061270a565b60006105d4825490565b6000818152600183016020526040812054611c4c575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556105d4565b5060006105d4565b600081831015611c64578161072e565b5090919050565b611c758282610b03565b6107b457611c8d816001600160a01b03166014611e4c565b611c98836020611e4c565b604051602001611ca9929190612662565b60408051601f198184030181529082905262461bcd60e51b82526107a1916004016126d7565b611cd98282610b03565b156107b4576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600061072e836001600160a01b038416611fe8565b6040516001600160a01b0383166024820152604481018290526105aa90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526120db565b6000826000018281548110611dc357611dc3612924565b9060005260206000200154905092915050565b60035460ff16610e7a5760405162461bcd60e51b8152602060048201526009602482015268217374616b61626c6560b81b60448201526064016107a1565b6040516001600160a01b0380851660248301528316604482015260648101829052610a279085906323b872dd60e01b90608401611d75565b60606000611e5b836002612864565b611e6690600261282a565b67ffffffffffffffff811115611e7e57611e7e61293a565b6040519080825280601f01601f191660200182016040528015611ea8576020820181803683370190505b509050600360fc1b81600081518110611ec357611ec3612924565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110611ef257611ef2612924565b60200101906001600160f81b031916908160001a9053506000611f16846002612864565b611f2190600161282a565b90505b6001811115611f99576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110611f5557611f55612924565b1a60f81b828281518110611f6b57611f6b612924565b60200101906001600160f81b031916908160001a90535060049490941c93611f92816128c6565b9050611f24565b50831561072e5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016107a1565b600081815260018301602052604081205480156120d157600061200c600183612883565b855490915060009061202090600190612883565b905081811461208557600086600001828154811061204057612040612924565b906000526020600020015490508087600001848154811061206357612063612924565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806120965761209661290e565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506105d4565b60009150506105d4565b6000612130826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166121ad9092919063ffffffff16565b8051909150156105aa578080602001905181019061214e91906124a6565b6105aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016107a1565b6060610d108484600085856001600160a01b0385163b61220f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016107a1565b600080866001600160a01b0316858760405161222b9190612646565b60006040518083038185875af1925050503d8060008114612268576040519150601f19603f3d011682016040523d82523d6000602084013e61226d565b606091505b509150915061227d828286612288565b979650505050505050565b6060831561229757508161072e565b8251156122a75782518084602001fd5b8160405162461bcd60e51b81526004016107a191906126d7565b805163ffffffff811681146122d557600080fd5b919050565b6000602082840312156122ec57600080fd5b813561072e816129eb565b60006020828403121561230957600080fd5b815161072e816129eb565b60008060006060848603121561232957600080fd5b8335612334816129eb565b92506020840135612344816129eb565b929592945050506040919091013590565b6000806000806080858703121561236b57600080fd5b8435612376816129eb565b93506020850135612386816129eb565b93969395505050506040820135916060013590565b6000806000606084860312156123b057600080fd5b83356123bb816129eb565b95602085013595506040909401359392505050565b600060208083850312156123e357600080fd5b825167ffffffffffffffff808211156123fb57600080fd5b818501915085601f83011261240f57600080fd5b8151818111156124215761242161293a565b8060051b91506124328483016127ce565b8181528481019084860184860187018a101561244d57600080fd5b600095505b8386101561247c5780519450612467856129eb565b84835260019590950194918601918601612452565b5098975050505050505050565b60006020828403121561249b57600080fd5b813561072e81612a00565b6000602082840312156124b857600080fd5b815161072e81612a00565b6000602082840312156124d557600080fd5b5035919050565b600080604083850312156124ef57600080fd5b823591506020830135612501816129eb565b809150509250929050565b6000806040838503121561251f57600080fd5b50508035926020909101359150565b60006020828403121561254057600080fd5b81356001600160e01b03198116811461072e57600080fd5b60006080828403121561256a57600080fd5b50919050565b600060a0828403121561258257600080fd5b60405160a0810181811067ffffffffffffffff821117156125a5576125a561293a565b604052825161ffff811681146125ba57600080fd5b81526125c8602084016122c1565b60208201526125d9604084016122c1565b604082015260608301516001600160801b03811681146125f857600080fd5b60608201526080928301519281019290925250919050565b60006020828403121561262257600080fd5b813561072e81612a0e565b60006020828403121561263f57600080fd5b5051919050565b6000825161265881846020870161289a565b9190910192915050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161269a81601785016020880161289a565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516126cb81602884016020880161289a565b01602801949350505050565b60208152600082518060208401526126f681604085016020870161289a565b601f01601f19169190910160400192915050565b6020808252600a9082015269085d985b1a5908185b5d60b21b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60c0810161279c8285805163ffffffff1682526020808201516001600160701b039081169184019190915260409182015116910152565b825163ffffffff16606083015260208301516001600160701b03908116608084015260408401511660a083015261072e565b604051601f8201601f1916810167ffffffffffffffff811182821017156127f7576127f761293a565b604052919050565b60006001600160701b03808316818516808303821115612821576128216128f8565b01949350505050565b6000821982111561283d5761283d6128f8565b500190565b60008261285f57634e487b7160e01b600052601260045260246000fd5b500490565b600081600019048311821515161561287e5761287e6128f8565b500290565b600082821015612895576128956128f8565b500390565b60005b838110156128b557818101518382015260200161289d565b83811115610a275750506000910152565b6000816128d5576128d56128f8565b506000190190565b60006000198214156128f1576128f16128f8565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b813561295b81612a00565b815460ff19811691151560ff169182178355602084013561297b81612a0e565b6effffffffffffffffffffffffffff008160081b16905080836effffffffffffffffffffffffffffff1984161717845560408501356129b981612a0e565b6001600160701b0360781b8160781b168462ffffff60e81b851617831717855550505050606082013560018201555050565b6001600160a01b038116811461119a57600080fd5b801515811461119a57600080fd5b6001600160701b038116811461119a57600080fdfe55d22ea8999f05fff67e43a978512ec7ffe546f7d94838b05a61eec6331cb66b1a551cd61c9ca3548d550e89120a4124f1c6e3ebe986e9e808beb1260b5b7d57a264697066735822122062ddf0cb8ff008d1c74682a0ef7d52d48940cae9c41c282a329b3eb86caef71e64736f6c63430008060033b9e206fa2af7ee1331b72ce58b6d938ac810ce9b5cdb65d35ab723fd67badf9e

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Validator ID :
0 FTM

Amount Staked
0

Amount Delegated
0

Staking Total
0

Staking Start Epoch
0

Staking Start Time
0

Proof of Importance
0

Origination Score
0

Validation Score
0

Active
0

Online
0

Downtime
0 s
Address Amount claimed Rewards Created On Epoch Created On
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.