ETH Price: $1,977.42 (+0.84%)
Gas: 0.03 Gwei
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Age:1H
Reset Filter

Transaction Hash
Method
Block
From
To

There are no matching entries

Update your filters to view other transactions

Age:1H
Reset Filter

Advanced mode:
Parent Transaction Hash Method Block
From
To

There are no matching entries

Update your filters to view other transactions

View All Internal Transactions
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
StakedAaveV3

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {IERC20} from '../interfaces/IERC20.sol';
import {DistributionTypes} from '../lib/DistributionTypes.sol';
import {GovernancePowerDelegationERC20} from '../lib/GovernancePowerDelegationERC20.sol';
import {StakedTokenV3} from './StakedTokenV3.sol';
import {IGhoVariableDebtTokenTransferHook} from '../interfaces/IGhoVariableDebtTokenTransferHook.sol';
import {SafeCast} from '../lib/SafeCast.sol';
import {IStakedAaveV3} from '../interfaces/IStakedAaveV3.sol';
import {IERC20WithPermit} from '../interfaces/IERC20WithPermit.sol';

/**
 * @title StakedAaveV3
 * @notice StakedTokenV3 with AAVE token as staked token
 * @author BGD Labs
 */
contract StakedAaveV3 is StakedTokenV3, IStakedAaveV3 {
  using SafeCast for uint256;

  uint32 internal _exchangeRateSnapshotsCount;
  /// @notice Snapshots of the exchangeRate for a given block
  mapping(uint256 => ExchangeRateSnapshot) internal _exchangeRateSnapshots;

  /// @notice GHO debt token to be used in the _beforeTokenTransfer hook
  IGhoVariableDebtTokenTransferHook public ghoDebtToken;

  function REVISION() public pure virtual override returns (uint256) {
    return 5;
  }

  constructor(
    IERC20 stakedToken,
    IERC20 rewardToken,
    uint256 unstakeWindow,
    address rewardsVault,
    address emissionManager,
    uint128 distributionDuration
  )
    StakedTokenV3(
      stakedToken,
      rewardToken,
      unstakeWindow,
      rewardsVault,
      emissionManager,
      distributionDuration
    )
  {
    // brick initialize
    lastInitializedRevision = REVISION();
  }

  /**
   * @dev Called by the proxy contract
   */
  function initialize(
    address slashingAdmin,
    address cooldownPauseAdmin,
    address claimHelper,
    uint256 maxSlashablePercentage,
    uint256 cooldownSeconds
  ) external override initializer {
    _initialize(
      slashingAdmin,
      cooldownPauseAdmin,
      claimHelper,
      maxSlashablePercentage,
      cooldownSeconds
    );

    // needed to claimRewardsAndStake works without a custom approval each time
    STAKED_TOKEN.approve(address(this), type(uint256).max);
  }

  /// @inheritdoc IStakedAaveV3
  function setGHODebtToken(IGhoVariableDebtTokenTransferHook newGHODebtToken)
    external
  {
    require(msg.sender == 0xEE56e2B3D491590B5b31738cC34d5232F378a8D5); // Short executor
    ghoDebtToken = newGHODebtToken;
    emit GHODebtTokenChanged(address(newGHODebtToken));
  }

  /// @inheritdoc IStakedAaveV3
  function claimRewardsAndStake(address to, uint256 amount)
    external
    override
    returns (uint256)
  {
    return _claimRewardsAndStakeOnBehalf(msg.sender, to, amount);
  }

  /// @inheritdoc IStakedAaveV3
  function claimRewardsAndStakeOnBehalf(
    address from,
    address to,
    uint256 amount
  ) external override onlyClaimHelper returns (uint256) {
    return _claimRewardsAndStakeOnBehalf(from, to, amount);
  }

  /// @inheritdoc IStakedAaveV3
  function stakeWithPermit(
    address from,
    uint256 amount,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) external override {
    IERC20WithPermit(address(STAKED_TOKEN)).permit(
      from,
      address(this),
      amount,
      deadline,
      v,
      r,
      s
    );
    _stake(from, from, amount);
  }

  /// @inheritdoc IStakedAaveV3
  function getExchangeRateSnapshotsCount() external view returns (uint32) {
    return _exchangeRateSnapshotsCount;
  }

  /// @inheritdoc IStakedAaveV3
  function getExchangeRateSnapshot(uint32 index)
    external
    view
    returns (ExchangeRateSnapshot memory)
  {
    return _exchangeRateSnapshots[index];
  }

  /**
   * @dev Writes a snapshot before any operation involving transfer of value: _transfer, _mint and _burn
   * - On _transfer, it writes snapshots for both "from" and "to"
   * - On _mint, only for _to
   * - On _burn, only for _from
   * @param from the from address
   * @param to the to address
   * @param amount the amount to transfer
   */
  function _beforeTokenTransfer(
    address from,
    address to,
    uint256 amount
  ) internal override {
    IGhoVariableDebtTokenTransferHook cachedGhoDebtToken = ghoDebtToken;
    if (address(cachedGhoDebtToken) != address(0)) {
      try
        cachedGhoDebtToken.updateDiscountDistribution(
          from,
          to,
          balanceOf(from),
          balanceOf(to),
          amount
        )
      {} catch (bytes memory) {}
    }
    address votingFromDelegatee = _votingDelegates[from];
    address votingToDelegatee = _votingDelegates[to];

    if (votingFromDelegatee == address(0)) {
      votingFromDelegatee = from;
    }
    if (votingToDelegatee == address(0)) {
      votingToDelegatee = to;
    }

    _moveDelegatesByType(
      votingFromDelegatee,
      votingToDelegatee,
      amount,
      DelegationType.VOTING_POWER
    );

    address propPowerFromDelegatee = _propositionPowerDelegates[from];
    address propPowerToDelegatee = _propositionPowerDelegates[to];

    if (propPowerFromDelegatee == address(0)) {
      propPowerFromDelegatee = from;
    }
    if (propPowerToDelegatee == address(0)) {
      propPowerToDelegatee = to;
    }

    _moveDelegatesByType(
      propPowerFromDelegatee,
      propPowerToDelegatee,
      amount,
      DelegationType.PROPOSITION_POWER
    );
  }

  /// @dev Modified version accounting for exchange rate at block
  /// @inheritdoc GovernancePowerDelegationERC20
  function _searchByBlockNumber(
    mapping(address => mapping(uint256 => Snapshot)) storage snapshots,
    mapping(address => uint256) storage snapshotsCounts,
    address user,
    uint256 blockNumber
  ) internal view override returns (uint256) {
    return
      (super._searchByBlockNumber(
        snapshots,
        snapshotsCounts,
        user,
        blockNumber
      ) * EXCHANGE_RATE_UNIT) /
      _binarySearchExchangeRate(
        _exchangeRateSnapshots,
        _exchangeRateSnapshotsCount,
        blockNumber
      );
  }

  /**
   * @dev Updates the exchangeRate and emits events accordingly
   * @param newExchangeRate the new exchange rate
   */
  function _updateExchangeRate(uint216 newExchangeRate) internal override {
    _exchangeRateSnapshots[_exchangeRateSnapshotsCount] = ExchangeRateSnapshot(
      block.number.toUint40(),
      newExchangeRate
    );
    ++_exchangeRateSnapshotsCount;
    super._updateExchangeRate(newExchangeRate);
  }

  function _binarySearchExchangeRate(
    mapping(uint256 => ExchangeRateSnapshot) storage snapshots,
    uint256 snapshotsCount,
    uint256 blockNumber
  ) internal view returns (uint256) {
    unchecked {
      // First check most recent balance
      if (snapshots[snapshotsCount - 1].blockNumber <= blockNumber) {
        return snapshots[snapshotsCount - 1].value;
      }

      uint256 lower = 0;
      uint256 upper = snapshotsCount - 1;
      while (upper > lower) {
        uint256 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
        ExchangeRateSnapshot memory snapshot = snapshots[center];
        if (snapshot.blockNumber == blockNumber) {
          return snapshot.value;
        } else if (snapshot.blockNumber < blockNumber) {
          lower = center;
        } else {
          upper = center - 1;
        }
      }
      return snapshots[lower].value;
    }
  }
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {DistributionTypes} from '../lib/DistributionTypes.sol';

/**
 * @title AaveDistributionManager
 * @notice Accounting contract to manage multiple staking distributions
 * @author Aave
 */
contract AaveDistributionManager {
  struct AssetData {
    uint128 emissionPerSecond;
    uint128 lastUpdateTimestamp;
    uint256 index;
    mapping(address => uint256) users;
  }

  uint256 public immutable DISTRIBUTION_END;

  address public immutable EMISSION_MANAGER;

  uint8 public constant PRECISION = 18;

  mapping(address => AssetData) public assets;

  event AssetConfigUpdated(address indexed asset, uint256 emission);
  event AssetIndexUpdated(address indexed asset, uint256 index);
  event UserIndexUpdated(
    address indexed user,
    address indexed asset,
    uint256 index
  );

  constructor(address emissionManager, uint256 distributionDuration) {
    DISTRIBUTION_END = block.timestamp + distributionDuration;
    EMISSION_MANAGER = emissionManager;
  }

  /**
   * @dev Configures the distribution of rewards for a list of assets
   * @param assetsConfigInput The list of configurations to apply
   */
  function _configureAssets(
    DistributionTypes.AssetConfigInput[] memory assetsConfigInput
  ) internal {
    for (uint256 i = 0; i < assetsConfigInput.length; i++) {
      AssetData storage assetConfig = assets[
        assetsConfigInput[i].underlyingAsset
      ];

      _updateAssetStateInternal(
        assetsConfigInput[i].underlyingAsset,
        assetConfig,
        assetsConfigInput[i].totalStaked
      );

      assetConfig.emissionPerSecond = assetsConfigInput[i].emissionPerSecond;

      emit AssetConfigUpdated(
        assetsConfigInput[i].underlyingAsset,
        assetsConfigInput[i].emissionPerSecond
      );
    }
  }

  /**
   * @dev Updates the state of one distribution, mainly rewards index and timestamp
   * @param underlyingAsset The address used as key in the distribution, for example sAAVE or the aTokens addresses on Aave
   * @param assetConfig Storage pointer to the distribution's config
   * @param totalStaked Current total of staked assets for this distribution
   * @return The new distribution index
   */
  function _updateAssetStateInternal(
    address underlyingAsset,
    AssetData storage assetConfig,
    uint256 totalStaked
  ) internal returns (uint256) {
    uint256 oldIndex = assetConfig.index;
    uint128 lastUpdateTimestamp = assetConfig.lastUpdateTimestamp;

    if (block.timestamp == lastUpdateTimestamp) {
      return oldIndex;
    }

    uint256 newIndex = _getAssetIndex(
      oldIndex,
      assetConfig.emissionPerSecond,
      lastUpdateTimestamp,
      totalStaked
    );

    if (newIndex != oldIndex) {
      assetConfig.index = newIndex;
      emit AssetIndexUpdated(underlyingAsset, newIndex);
    }

    assetConfig.lastUpdateTimestamp = uint128(block.timestamp);

    return newIndex;
  }

  /**
   * @dev Updates the state of an user in a distribution
   * @param user The user's address
   * @param asset The address of the reference asset of the distribution
   * @param stakedByUser Amount of tokens staked by the user in the distribution at the moment
   * @param totalStaked Total tokens staked in the distribution
   * @return The accrued rewards for the user until the moment
   */
  function _updateUserAssetInternal(
    address user,
    address asset,
    uint256 stakedByUser,
    uint256 totalStaked
  ) internal returns (uint256) {
    AssetData storage assetData = assets[asset];
    uint256 userIndex = assetData.users[user];
    uint256 accruedRewards = 0;

    uint256 newIndex = _updateAssetStateInternal(asset, assetData, totalStaked);

    if (userIndex != newIndex) {
      if (stakedByUser != 0) {
        accruedRewards = _getRewards(stakedByUser, newIndex, userIndex);
      }

      assetData.users[user] = newIndex;
      emit UserIndexUpdated(user, asset, newIndex);
    }

    return accruedRewards;
  }

  /**
   * @dev Used by "frontend" stake contracts to update the data of an user when claiming rewards from there
   * @param user The address of the user
   * @param stakes List of structs of the user data related with his stake
   * @return The accrued rewards for the user until the moment
   */
  function _claimRewards(
    address user,
    DistributionTypes.UserStakeInput[] memory stakes
  ) internal returns (uint256) {
    uint256 accruedRewards = 0;

    for (uint256 i = 0; i < stakes.length; i++) {
      accruedRewards =
        accruedRewards +
        _updateUserAssetInternal(
          user,
          stakes[i].underlyingAsset,
          stakes[i].stakedByUser,
          stakes[i].totalStaked
        );
    }

    return accruedRewards;
  }

  /**
   * @dev Return the accrued rewards for an user over a list of distribution
   * @param user The address of the user
   * @param stakes List of structs of the user data related with his stake
   * @return The accrued rewards for the user until the moment
   */
  function _getUnclaimedRewards(
    address user,
    DistributionTypes.UserStakeInput[] memory stakes
  ) internal view returns (uint256) {
    uint256 accruedRewards = 0;

    for (uint256 i = 0; i < stakes.length; i++) {
      AssetData storage assetConfig = assets[stakes[i].underlyingAsset];
      uint256 assetIndex = _getAssetIndex(
        assetConfig.index,
        assetConfig.emissionPerSecond,
        assetConfig.lastUpdateTimestamp,
        stakes[i].totalStaked
      );

      accruedRewards =
        accruedRewards +
        _getRewards(
          stakes[i].stakedByUser,
          assetIndex,
          assetConfig.users[user]
        );
    }
    return accruedRewards;
  }

  /**
   * @dev Internal function for the calculation of user's rewards on a distribution
   * @param principalUserBalance Amount staked by the user on a distribution
   * @param reserveIndex Current index of the distribution
   * @param userIndex Index stored for the user, representation his staking moment
   * @return The rewards
   */
  function _getRewards(
    uint256 principalUserBalance,
    uint256 reserveIndex,
    uint256 userIndex
  ) internal pure returns (uint256) {
    return
      (principalUserBalance * (reserveIndex - userIndex)) /
      (10**uint256(PRECISION));
  }

  /**
   * @dev Calculates the next value of an specific distribution index, with validations
   * @param currentIndex Current index of the distribution
   * @param emissionPerSecond Representing the total rewards distributed per second per asset unit, on the distribution
   * @param lastUpdateTimestamp Last moment this distribution was updated
   * @param totalBalance of tokens considered for the distribution
   * @return The new index.
   */
  function _getAssetIndex(
    uint256 currentIndex,
    uint256 emissionPerSecond,
    uint128 lastUpdateTimestamp,
    uint256 totalBalance
  ) internal view returns (uint256) {
    if (
      emissionPerSecond == 0 ||
      totalBalance == 0 ||
      lastUpdateTimestamp == block.timestamp ||
      lastUpdateTimestamp >= DISTRIBUTION_END
    ) {
      return currentIndex;
    }

    uint256 currentTimestamp = block.timestamp > DISTRIBUTION_END
      ? DISTRIBUTION_END
      : block.timestamp;
    uint256 timeDelta = currentTimestamp - lastUpdateTimestamp;
    return
      ((emissionPerSecond * timeDelta * (10**uint256(PRECISION))) /
        totalBalance) + currentIndex;
  }

  /**
   * @dev Returns the data of an user on a distribution
   * @param user Address of the user
   * @param asset The address of the reference asset of the distribution
   * @return The new index
   */
  function getUserAssetData(address user, address asset)
    public
    view
    returns (uint256)
  {
    return assets[asset].users[user];
  }
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {IERC20} from '../interfaces/IERC20.sol';
import {IStakedTokenV2} from '../interfaces/IStakedTokenV2.sol';

import {ERC20} from '../lib/ERC20.sol';
import {DistributionTypes} from '../lib/DistributionTypes.sol';
import {SafeERC20} from '../lib/SafeERC20.sol';

import {VersionedInitializable} from '../utils/VersionedInitializable.sol';
import {AaveDistributionManager} from './AaveDistributionManager.sol';
import {GovernancePowerWithSnapshot} from '../lib/GovernancePowerWithSnapshot.sol';

/**
 * @title StakedTokenV2
 * @notice Contract to stake Aave token, tokenize the position and get rewards, inheriting from a distribution manager contract
 * @author BGD Labs
 */
abstract contract StakedTokenV2 is
  IStakedTokenV2,
  GovernancePowerWithSnapshot,
  VersionedInitializable,
  AaveDistributionManager
{
  using SafeERC20 for IERC20;

  IERC20 public immutable STAKED_TOKEN;
  IERC20 public immutable REWARD_TOKEN;

  /// @notice Seconds available to redeem once the cooldown period is fulfilled
  uint256 public immutable UNSTAKE_WINDOW;

  /// @notice Address to pull from the rewards, needs to have approved this contract
  address public immutable REWARDS_VAULT;

  mapping(address => uint256) public stakerRewardsToClaim;
  mapping(address => CooldownSnapshot) public stakersCooldowns;

  /// @dev End of Storage layout from StakedToken v1

  /// @dev To see the voting mappings, go to GovernancePowerWithSnapshot.sol
  mapping(address => address) internal _votingDelegates;

  mapping(address => mapping(uint256 => Snapshot))
    internal _propositionPowerSnapshots;
  mapping(address => uint256) internal _propositionPowerSnapshotsCounts;
  mapping(address => address) internal _propositionPowerDelegates;

  bytes32 public DOMAIN_SEPARATOR;
  bytes public constant EIP712_REVISION = bytes('1');
  bytes32 internal constant EIP712_DOMAIN =
    keccak256(
      'EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'
    );
  bytes32 public constant PERMIT_TYPEHASH =
    keccak256(
      'Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)'
    );

  /// @dev owner => next valid nonce to submit with permit()
  mapping(address => uint256) public _nonces;

  constructor(
    IERC20 stakedToken,
    IERC20 rewardToken,
    uint256 unstakeWindow,
    address rewardsVault,
    address emissionManager,
    uint128 distributionDuration
  ) ERC20() AaveDistributionManager(emissionManager, distributionDuration) {
    STAKED_TOKEN = stakedToken;
    REWARD_TOKEN = rewardToken;
    UNSTAKE_WINDOW = unstakeWindow;
    REWARDS_VAULT = rewardsVault;
  }

  /// @inheritdoc IStakedTokenV2
  function stake(address onBehalfOf, uint256 amount) external virtual override;

  /// @inheritdoc IStakedTokenV2
  function redeem(address to, uint256 amount) external virtual override;

  /// @inheritdoc IStakedTokenV2
  function cooldown() external virtual override;

  /// @inheritdoc IStakedTokenV2
  function claimRewards(address to, uint256 amount) external virtual override;

  /// @inheritdoc IStakedTokenV2
  function getTotalRewardsBalance(address staker)
    external
    view
    returns (uint256)
  {
    DistributionTypes.UserStakeInput[]
      memory userStakeInputs = new DistributionTypes.UserStakeInput[](1);
    userStakeInputs[0] = DistributionTypes.UserStakeInput({
      underlyingAsset: address(this),
      stakedByUser: balanceOf(staker),
      totalStaked: totalSupply()
    });
    return
      stakerRewardsToClaim[staker] +
      _getUnclaimedRewards(staker, userStakeInputs);
  }

  /// @inheritdoc IStakedTokenV2
  function permit(
    address owner,
    address spender,
    uint256 value,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) external {
    require(owner != address(0), 'INVALID_OWNER');
    //solium-disable-next-line
    require(block.timestamp <= deadline, 'INVALID_EXPIRATION');
    uint256 currentValidNonce = _nonces[owner];
    bytes32 digest = keccak256(
      abi.encodePacked(
        '\x19\x01',
        DOMAIN_SEPARATOR,
        keccak256(
          abi.encode(
            PERMIT_TYPEHASH,
            owner,
            spender,
            value,
            currentValidNonce,
            deadline
          )
        )
      )
    );

    require(owner == ecrecover(digest, v, r, s), 'INVALID_SIGNATURE');
    unchecked {
      _nonces[owner] = currentValidNonce + 1;
    }
    _approve(owner, spender, value);
  }

  /**
   * @dev Delegates power from signatory to `delegatee`
   * @param delegatee The address to delegate votes to
   * @param delegationType the type of delegation (VOTING_POWER, PROPOSITION_POWER)
   * @param nonce The contract state required to match the signature
   * @param expiry The time at which to expire the signature
   * @param v The recovery byte of the signature
   * @param r Half of the ECDSA signature pair
   * @param s Half of the ECDSA signature pair
   */
  function delegateByTypeBySig(
    address delegatee,
    DelegationType delegationType,
    uint256 nonce,
    uint256 expiry,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) public {
    bytes32 structHash = keccak256(
      abi.encode(
        DELEGATE_BY_TYPE_TYPEHASH,
        delegatee,
        uint256(delegationType),
        nonce,
        expiry
      )
    );
    bytes32 digest = keccak256(
      abi.encodePacked('\x19\x01', DOMAIN_SEPARATOR, structHash)
    );
    address signatory = ecrecover(digest, v, r, s);
    require(signatory != address(0), 'INVALID_SIGNATURE');
    require(nonce == _nonces[signatory]++, 'INVALID_NONCE');
    require(block.timestamp <= expiry, 'INVALID_EXPIRATION');
    _delegateByType(signatory, delegatee, delegationType);
  }

  /**
   * @dev Delegates power from signatory to `delegatee`
   * @param delegatee The address to delegate votes to
   * @param nonce The contract state required to match the signature
   * @param expiry The time at which to expire the signature
   * @param v The recovery byte of the signature
   * @param r Half of the ECDSA signature pair
   * @param s Half of the ECDSA signature pair
   */
  function delegateBySig(
    address delegatee,
    uint256 nonce,
    uint256 expiry,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) public {
    bytes32 structHash = keccak256(
      abi.encode(DELEGATE_TYPEHASH, delegatee, nonce, expiry)
    );
    bytes32 digest = keccak256(
      abi.encodePacked('\x19\x01', DOMAIN_SEPARATOR, structHash)
    );
    address signatory = ecrecover(digest, v, r, s);
    require(signatory != address(0), 'INVALID_SIGNATURE');
    require(nonce == _nonces[signatory]++, 'INVALID_NONCE');
    require(block.timestamp <= expiry, 'INVALID_EXPIRATION');
    _delegateByType(signatory, delegatee, DelegationType.VOTING_POWER);
    _delegateByType(signatory, delegatee, DelegationType.PROPOSITION_POWER);
  }

  /**
   * @dev Updates the user state related with his accrued rewards
   * @param user Address of the user
   * @param userBalance The current balance of the user
   * @param updateStorage Boolean flag used to update or not the stakerRewardsToClaim of the user
   * @return The unclaimed rewards that were added to the total accrued
   */
  function _updateCurrentUnclaimedRewards(
    address user,
    uint256 userBalance,
    bool updateStorage
  ) internal returns (uint256) {
    uint256 accruedRewards = _updateUserAssetInternal(
      user,
      address(this),
      userBalance,
      totalSupply()
    );
    uint256 unclaimedRewards = stakerRewardsToClaim[user] + accruedRewards;

    if (accruedRewards != 0) {
      if (updateStorage) {
        stakerRewardsToClaim[user] = unclaimedRewards;
      }
      emit RewardsAccrued(user, accruedRewards);
    }

    return unclaimedRewards;
  }

  /**
   * @dev returns relevant storage slots for a DelegationType
   * @param delegationType the requested DelegationType
   * @return the relevant storage
   */
  function _getDelegationDataByType(DelegationType delegationType)
    internal
    view
    override
    returns (
      mapping(address => mapping(uint256 => Snapshot)) storage, //snapshots
      mapping(address => uint256) storage, //snapshots count
      mapping(address => address) storage //delegatees list
    )
  {
    if (delegationType == DelegationType.VOTING_POWER) {
      return (_votingSnapshots, _votingSnapshotsCounts, _votingDelegates);
    } else {
      return (
        _propositionPowerSnapshots,
        _propositionPowerSnapshotsCounts,
        _propositionPowerDelegates
      );
    }
  }
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {IERC20} from '../interfaces/IERC20.sol';
import {DistributionTypes} from '../lib/DistributionTypes.sol';
import {SafeERC20} from '../lib/SafeERC20.sol';
import {IAaveDistributionManager} from '../interfaces/IAaveDistributionManager.sol';
import {IERC20Metadata} from '../interfaces/IERC20Metadata.sol';
import {IStakedTokenV2} from '../interfaces/IStakedTokenV2.sol';
import {StakedTokenV2} from './StakedTokenV2.sol';
import {IStakedTokenV3} from '../interfaces/IStakedTokenV3.sol';
import {PercentageMath} from '../lib/PercentageMath.sol';
import {RoleManager} from '../utils/RoleManager.sol';
import {SafeCast} from '../lib/SafeCast.sol';

/**
 * @title StakedTokenV3
 * @notice Contract to stake Aave token, tokenize the position and get rewards, inheriting from a distribution manager contract
 * @author BGD Labs
 */
contract StakedTokenV3 is
  StakedTokenV2,
  IStakedTokenV3,
  RoleManager,
  IAaveDistributionManager
{
  using SafeERC20 for IERC20;
  using PercentageMath for uint256;
  using SafeCast for uint256;

  uint256 public constant SLASH_ADMIN_ROLE = 0;
  uint256 public constant COOLDOWN_ADMIN_ROLE = 1;
  uint256 public constant CLAIM_HELPER_ROLE = 2;
  uint216 public constant INITIAL_EXCHANGE_RATE = 1e18;
  uint256 public constant EXCHANGE_RATE_UNIT = 1e18;

  /// @notice lower bound to prevent spam & avoid exchangeRate issues
  // as returnFunds can be called permissionless an attacker could spam returnFunds(1) to produce exchangeRate snapshots making voting expensive
  uint256 public immutable LOWER_BOUND;

  // Reserved storage space to allow for layout changes in the future.
  uint256[8] private ______gap;
  /// @notice Seconds between starting cooldown and being able to withdraw
  uint256 internal _cooldownSeconds;
  /// @notice The maximum amount of funds that can be slashed at any given time
  uint256 internal _maxSlashablePercentage;
  /// @notice Mirror of latest snapshot value for cheaper access
  uint216 internal _currentExchangeRate;
  /// @notice Flag determining if there's an ongoing slashing event that needs to be settled
  bool public inPostSlashingPeriod;

  modifier onlySlashingAdmin() {
    require(
      msg.sender == getAdmin(SLASH_ADMIN_ROLE),
      'CALLER_NOT_SLASHING_ADMIN'
    );
    _;
  }

  modifier onlyCooldownAdmin() {
    require(
      msg.sender == getAdmin(COOLDOWN_ADMIN_ROLE),
      'CALLER_NOT_COOLDOWN_ADMIN'
    );
    _;
  }

  modifier onlyClaimHelper() {
    require(
      msg.sender == getAdmin(CLAIM_HELPER_ROLE),
      'CALLER_NOT_CLAIM_HELPER'
    );
    _;
  }

  constructor(
    IERC20 stakedToken,
    IERC20 rewardToken,
    uint256 unstakeWindow,
    address rewardsVault,
    address emissionManager,
    uint128 distributionDuration
  )
    StakedTokenV2(
      stakedToken,
      rewardToken,
      unstakeWindow,
      rewardsVault,
      emissionManager,
      distributionDuration
    )
  {
    // brick initialize
    lastInitializedRevision = REVISION();
    uint256 decimals = IERC20Metadata(address(stakedToken)).decimals();
    LOWER_BOUND = 10**decimals;
  }

  /**
   * @dev returns the revision of the implementation contract
   * @return The revision
   */
  function REVISION() public pure virtual returns (uint256) {
    return 3;
  }

  /**
   * @dev returns the revision of the implementation contract
   * @return The revision
   */
  function getRevision() internal pure virtual override returns (uint256) {
    return REVISION();
  }

  /**
   * @dev Called by the proxy contract
   */
  function initialize(
    address slashingAdmin,
    address cooldownPauseAdmin,
    address claimHelper,
    uint256 maxSlashablePercentage,
    uint256 cooldownSeconds
  ) external virtual initializer {
    _initialize(
      slashingAdmin,
      cooldownPauseAdmin,
      claimHelper,
      maxSlashablePercentage,
      cooldownSeconds
    );
  }

  function _initialize(
    address slashingAdmin,
    address cooldownPauseAdmin,
    address claimHelper,
    uint256 maxSlashablePercentage,
    uint256 cooldownSeconds
  ) internal {
    InitAdmin[] memory initAdmins = new InitAdmin[](3);
    initAdmins[0] = InitAdmin(SLASH_ADMIN_ROLE, slashingAdmin);
    initAdmins[1] = InitAdmin(COOLDOWN_ADMIN_ROLE, cooldownPauseAdmin);
    initAdmins[2] = InitAdmin(CLAIM_HELPER_ROLE, claimHelper);

    _initAdmins(initAdmins);

    _setMaxSlashablePercentage(maxSlashablePercentage);
    _setCooldownSeconds(cooldownSeconds);
    _updateExchangeRate(INITIAL_EXCHANGE_RATE);
  }

  /// @inheritdoc IAaveDistributionManager
  function configureAssets(
    DistributionTypes.AssetConfigInput[] memory assetsConfigInput
  ) external override {
    require(msg.sender == EMISSION_MANAGER, 'ONLY_EMISSION_MANAGER');

    for (uint256 i = 0; i < assetsConfigInput.length; i++) {
      assetsConfigInput[i].totalStaked = totalSupply();
    }

    _configureAssets(assetsConfigInput);
  }

  /// @inheritdoc IStakedTokenV3
  function previewStake(uint256 assets) public view returns (uint256) {
    return (assets * _currentExchangeRate) / EXCHANGE_RATE_UNIT;
  }

  /// @inheritdoc IStakedTokenV2
  function stake(address to, uint256 amount)
    external
    override(IStakedTokenV2, StakedTokenV2)
  {
    _stake(msg.sender, to, amount);
  }

  /// @inheritdoc IStakedTokenV2
  function cooldown() external override(IStakedTokenV2, StakedTokenV2) {
    _cooldown(msg.sender);
  }

  /// @inheritdoc IStakedTokenV3
  function cooldownOnBehalfOf(address from) external override onlyClaimHelper {
    _cooldown(from);
  }

  function _cooldown(address from) internal {
    uint256 amount = balanceOf(from);
    require(amount != 0, 'INVALID_BALANCE_ON_COOLDOWN');
    stakersCooldowns[from] = CooldownSnapshot({
      timestamp: uint40(block.timestamp),
      amount: uint216(amount)
    });

    emit Cooldown(from, amount);
  }

  /// @inheritdoc IStakedTokenV2
  function redeem(address to, uint256 amount)
    external
    override(IStakedTokenV2, StakedTokenV2)
  {
    _redeem(msg.sender, to, amount);
  }

  /// @inheritdoc IStakedTokenV3
  function redeemOnBehalf(
    address from,
    address to,
    uint256 amount
  ) external override onlyClaimHelper {
    _redeem(from, to, amount);
  }

  /// @inheritdoc IStakedTokenV2
  function claimRewards(address to, uint256 amount)
    external
    override(IStakedTokenV2, StakedTokenV2)
  {
    _claimRewards(msg.sender, to, amount);
  }

  /// @inheritdoc IStakedTokenV3
  function claimRewardsOnBehalf(
    address from,
    address to,
    uint256 amount
  ) external override onlyClaimHelper returns (uint256) {
    return _claimRewards(from, to, amount);
  }

  /// @inheritdoc IStakedTokenV3
  function claimRewardsAndRedeem(
    address to,
    uint256 claimAmount,
    uint256 redeemAmount
  ) external override {
    _claimRewards(msg.sender, to, claimAmount);
    _redeem(msg.sender, to, redeemAmount);
  }

  /// @inheritdoc IStakedTokenV3
  function claimRewardsAndRedeemOnBehalf(
    address from,
    address to,
    uint256 claimAmount,
    uint256 redeemAmount
  ) external override onlyClaimHelper {
    _claimRewards(from, to, claimAmount);
    _redeem(from, to, redeemAmount);
  }

  /// @inheritdoc IStakedTokenV3
  function getExchangeRate() public view override returns (uint216) {
    return _currentExchangeRate;
  }

  /// @inheritdoc IStakedTokenV3
  function previewRedeem(uint256 shares)
    public
    view
    override
    returns (uint256)
  {
    return (EXCHANGE_RATE_UNIT * shares) / _currentExchangeRate;
  }

  /// @inheritdoc IStakedTokenV3
  function slash(address destination, uint256 amount)
    external
    override
    onlySlashingAdmin
    returns (uint256)
  {
    require(!inPostSlashingPeriod, 'PREVIOUS_SLASHING_NOT_SETTLED');
    require(amount > 0, 'ZERO_AMOUNT');
    uint256 currentShares = totalSupply();
    uint256 balance = previewRedeem(currentShares);

    uint256 maxSlashable = balance.percentMul(_maxSlashablePercentage);

    if (amount > maxSlashable) {
      amount = maxSlashable;
    }
    require(balance - amount >= LOWER_BOUND, 'REMAINING_LT_MINIMUM');

    inPostSlashingPeriod = true;
    _updateExchangeRate(_getExchangeRate(balance - amount, currentShares));

    STAKED_TOKEN.safeTransfer(destination, amount);

    emit Slashed(destination, amount);
    return amount;
  }

  /// @inheritdoc IStakedTokenV3
  function returnFunds(uint256 amount) external override {
    require(amount >= LOWER_BOUND, 'AMOUNT_LT_MINIMUM');
    uint256 currentShares = totalSupply();
    require(currentShares >= LOWER_BOUND, 'SHARES_LT_MINIMUM');
    uint256 assets = previewRedeem(currentShares);
    _updateExchangeRate(_getExchangeRate(assets + amount, currentShares));

    STAKED_TOKEN.safeTransferFrom(msg.sender, address(this), amount);
    emit FundsReturned(amount);
  }

  /// @inheritdoc IStakedTokenV3
  function settleSlashing() external override onlySlashingAdmin {
    inPostSlashingPeriod = false;
    emit SlashingSettled();
  }

  /// @inheritdoc IStakedTokenV3
  function setMaxSlashablePercentage(uint256 percentage)
    external
    override
    onlySlashingAdmin
  {
    _setMaxSlashablePercentage(percentage);
  }

  /// @inheritdoc IStakedTokenV3
  function getMaxSlashablePercentage()
    external
    view
    override
    returns (uint256)
  {
    return _maxSlashablePercentage;
  }

  /// @inheritdoc IStakedTokenV3
  function setCooldownSeconds(uint256 cooldownSeconds)
    external
    onlyCooldownAdmin
  {
    _setCooldownSeconds(cooldownSeconds);
  }

  /// @inheritdoc IStakedTokenV3
  function getCooldownSeconds() external view returns (uint256) {
    return _cooldownSeconds;
  }

  /// @inheritdoc IStakedTokenV3
  function COOLDOWN_SECONDS() external view returns (uint256) {
    return _cooldownSeconds;
  }

  /**
   * @dev sets the max slashable percentage
   * @param percentage must be strictly lower 100% as otherwise the exchange rate calculation would result in 0 division
   */
  function _setMaxSlashablePercentage(uint256 percentage) internal {
    require(
      percentage < PercentageMath.PERCENTAGE_FACTOR,
      'INVALID_SLASHING_PERCENTAGE'
    );

    _maxSlashablePercentage = percentage;
    emit MaxSlashablePercentageChanged(percentage);
  }

  /**
   * @dev sets the cooldown seconds
   * @param cooldownSeconds the new amount of cooldown seconds
   */
  function _setCooldownSeconds(uint256 cooldownSeconds) internal {
    _cooldownSeconds = cooldownSeconds;
    emit CooldownSecondsChanged(cooldownSeconds);
  }

  /**
   * @dev claims the rewards for a specified address to a specified address
   * @param from The address of the from from which to claim
   * @param to Address to receive the rewards
   * @param amount Amount to claim
   * @return amount claimed
   */
  function _claimRewards(
    address from,
    address to,
    uint256 amount
  ) internal returns (uint256) {
    require(amount != 0, 'INVALID_ZERO_AMOUNT');
    uint256 newTotalRewards = _updateCurrentUnclaimedRewards(
      from,
      balanceOf(from),
      false
    );

    uint256 amountToClaim = (amount > newTotalRewards)
      ? newTotalRewards
      : amount;
    require(amountToClaim != 0, 'INVALID_ZERO_AMOUNT');

    stakerRewardsToClaim[from] = newTotalRewards - amountToClaim;
    REWARD_TOKEN.safeTransferFrom(REWARDS_VAULT, to, amountToClaim);
    emit RewardsClaimed(from, to, amountToClaim);
    return amountToClaim;
  }

  /**
   * @dev Claims an `amount` of `REWARD_TOKEN` and stakes.
   * @param from The address of the from from which to claim
   * @param to Address to stake to
   * @param amount Amount to claim
   * @return amount claimed
   */
  function _claimRewardsAndStakeOnBehalf(
    address from,
    address to,
    uint256 amount
  ) internal returns (uint256) {
    require(REWARD_TOKEN == STAKED_TOKEN, 'REWARD_TOKEN_IS_NOT_STAKED_TOKEN');

    uint256 userUpdatedRewards = _updateCurrentUnclaimedRewards(
      from,
      balanceOf(from),
      true
    );
    uint256 amountToClaim = (amount > userUpdatedRewards)
      ? userUpdatedRewards
      : amount;

    if (amountToClaim != 0) {
      _claimRewards(from, address(this), amountToClaim);
      _stake(address(this), to, amountToClaim);
    }

    return amountToClaim;
  }

  /**
   * @dev Allows staking a specified amount of STAKED_TOKEN
   * @param to The address to receiving the shares
   * @param amount The amount of assets to be staked
   */
  function _stake(
    address from,
    address to,
    uint256 amount
  ) internal {
    require(!inPostSlashingPeriod, 'SLASHING_ONGOING');
    require(amount != 0, 'INVALID_ZERO_AMOUNT');

    uint256 balanceOfTo = balanceOf(to);

    uint256 accruedRewards = _updateUserAssetInternal(
      to,
      address(this),
      balanceOfTo,
      totalSupply()
    );

    if (accruedRewards != 0) {
      stakerRewardsToClaim[to] = stakerRewardsToClaim[to] + accruedRewards;
      emit RewardsAccrued(to, accruedRewards);
    }

    uint256 sharesToMint = previewStake(amount);

    STAKED_TOKEN.safeTransferFrom(from, address(this), amount);

    _mint(to, sharesToMint);

    emit Staked(from, to, amount, sharesToMint);
  }

  /**
   * @dev Redeems staked tokens, and stop earning rewards
   * @param from Address to redeem from
   * @param to Address to redeem to
   * @param amount Amount to redeem
   */
  function _redeem(
    address from,
    address to,
    uint256 amount
  ) internal {
    require(amount != 0, 'INVALID_ZERO_AMOUNT');

    CooldownSnapshot memory cooldownSnapshot = stakersCooldowns[from];
    if (!inPostSlashingPeriod) {
      require(
        (block.timestamp > cooldownSnapshot.timestamp + _cooldownSeconds),
        'INSUFFICIENT_COOLDOWN'
      );
      require(
        (block.timestamp - (cooldownSnapshot.timestamp + _cooldownSeconds) <=
          UNSTAKE_WINDOW),
        'UNSTAKE_WINDOW_FINISHED'
      );
    }

    uint256 balanceOfFrom = balanceOf(from);
    uint256 maxRedeemable = inPostSlashingPeriod
      ? balanceOfFrom
      : cooldownSnapshot.amount;
    require(maxRedeemable != 0, 'INVALID_ZERO_MAX_REDEEMABLE');

    uint256 amountToRedeem = (amount > maxRedeemable) ? maxRedeemable : amount;

    _updateCurrentUnclaimedRewards(from, balanceOfFrom, true);

    uint256 underlyingToRedeem = previewRedeem(amountToRedeem);

    _burn(from, amountToRedeem);

    if (cooldownSnapshot.timestamp != 0) {
      if (cooldownSnapshot.amount - amountToRedeem == 0) {
        delete stakersCooldowns[from];
      } else {
        stakersCooldowns[from].amount =
          stakersCooldowns[from].amount -
          amountToRedeem.toUint184();
      }
    }

    IERC20(STAKED_TOKEN).safeTransfer(to, underlyingToRedeem);

    emit Redeem(from, to, underlyingToRedeem, amountToRedeem);
  }

  /**
   * @dev Updates the exchangeRate and emits events accordingly
   * @param newExchangeRate the new exchange rate
   */
  function _updateExchangeRate(uint216 newExchangeRate) internal virtual {
    require(newExchangeRate != 0, 'ZERO_EXCHANGE_RATE');
    _currentExchangeRate = newExchangeRate;
    emit ExchangeRateChanged(newExchangeRate);
  }

  /**
   * @dev calculates the exchange rate based on totalAssets and totalShares
   * @dev always rounds up to ensure 100% backing of shares by rounding in favor of the contract
   * @param totalAssets The total amount of assets staked
   * @param totalShares The total amount of shares
   * @return exchangeRate as 18 decimal precision uint216
   */
  function _getExchangeRate(uint256 totalAssets, uint256 totalShares)
    internal
    pure
    returns (uint216)
  {
    return
      (((totalShares * EXCHANGE_RATE_UNIT) + totalAssets - 1) / totalAssets)
        .toUint216();
  }

  function _transfer(
    address from,
    address to,
    uint256 amount
  ) internal override {
    uint256 balanceOfFrom = balanceOf(from);
    // Sender
    _updateCurrentUnclaimedRewards(from, balanceOfFrom, true);

    // Recipient
    if (from != to) {
      uint256 balanceOfTo = balanceOf(to);
      _updateCurrentUnclaimedRewards(to, balanceOfTo, true);

      CooldownSnapshot memory previousSenderCooldown = stakersCooldowns[from];
      if (previousSenderCooldown.timestamp != 0) {
        // if cooldown was set and whole balance of sender was transferred - clear cooldown
        if (balanceOfFrom == amount) {
          delete stakersCooldowns[from];
        } else if (balanceOfFrom - amount < previousSenderCooldown.amount) {
          stakersCooldowns[from].amount = uint184(balanceOfFrom - amount);
        }
      }
    }

    super._transfer(from, to, amount);
  }
}

File 5 of 25 : IAaveDistributionManager.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {DistributionTypes} from '../lib/DistributionTypes.sol';

interface IAaveDistributionManager {
  function configureAssets(
    DistributionTypes.AssetConfigInput[] memory assetsConfigInput
  ) external;
}

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import './IERC20.sol';

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

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

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

File 8 of 25 : IERC20WithPermit.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {IERC20} from './IERC20.sol';

interface IERC20WithPermit is IERC20 {
  function permit(
    address owner,
    address spender,
    uint256 value,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) external;
}

File 9 of 25 : IGhoVariableDebtTokenTransferHook.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

interface IGhoVariableDebtTokenTransferHook {
  /**
   * @dev updates the discount when discount token is transferred
   * @dev Only callable by discount token
   * @param sender address of sender
   * @param recipient address of recipient
   * @param senderDiscountTokenBalance sender discount token balance
   * @param recipientDiscountTokenBalance recipient discount token balance
   * @param amount amount of discount token being transferred
   **/
  function updateDiscountDistribution(
    address sender,
    address recipient,
    uint256 senderDiscountTokenBalance,
    uint256 recipientDiscountTokenBalance,
    uint256 amount
  ) external;
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

interface IGovernancePowerDelegationToken {
  enum DelegationType {
    VOTING_POWER,
    PROPOSITION_POWER
  }

  /**
   * @dev emitted when a user delegates to another
   * @param delegator the delegator
   * @param delegatee the delegatee
   * @param delegationType the type of delegation (VOTING_POWER, PROPOSITION_POWER)
   **/
  event DelegateChanged(
    address indexed delegator,
    address indexed delegatee,
    DelegationType delegationType
  );

  /**
   * @dev emitted when an action changes the delegated power of a user
   * @param user the user which delegated power has changed
   * @param amount the amount of delegated power for the user
   * @param delegationType the type of delegation (VOTING_POWER, PROPOSITION_POWER)
   **/
  event DelegatedPowerChanged(
    address indexed user,
    uint256 amount,
    DelegationType delegationType
  );

  /**
   * @dev delegates the specific power to a delegatee
   * @param delegatee the user which delegated power has changed
   * @param delegationType the type of delegation (VOTING_POWER, PROPOSITION_POWER)
   **/
  function delegateByType(address delegatee, DelegationType delegationType)
    external;

  /**
   * @dev delegates all the powers to a specific user
   * @param delegatee the user to which the power will be delegated
   **/
  function delegate(address delegatee) external;

  /**
   * @dev returns the delegatee of an user
   * @param delegator the address of the delegator
   **/
  function getDelegateeByType(address delegator, DelegationType delegationType)
    external
    view
    returns (address);

  /**
   * @dev returns the current delegated power of a user. The current power is the
   * power delegated at the time of the last snapshot
   * @param user the user
   **/
  function getPowerCurrent(address user, DelegationType delegationType)
    external
    view
    returns (uint256);

  /**
   * @dev returns the delegated power of a user at a certain block
   * @param user the user
   **/
  function getPowerAtBlock(
    address user,
    uint256 blockNumber,
    DelegationType delegationType
  ) external view returns (uint256);

  /**
   * @dev returns the total supply at a certain block number
   **/
  function totalSupplyAt(uint256 blockNumber) external view returns (uint256);
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {IStakedTokenV3} from './IStakedTokenV3.sol';
import {IGhoVariableDebtTokenTransferHook} from './IGhoVariableDebtTokenTransferHook.sol';

interface IStakedAaveV3 is IStakedTokenV3 {
  struct ExchangeRateSnapshot {
    uint40 blockNumber;
    uint216 value;
  }

  event GHODebtTokenChanged(address indexed newDebtToken);

  /**
   * @dev Returnes the number of excahngeRate snapshots
   */
  function getExchangeRateSnapshotsCount() external view returns (uint32);

  /**
   * @dev Returns the exchangeRate for a specified index
   * @param index Index of the exchangeRate
   */
  function getExchangeRateSnapshot(uint32 index)
    external
    view
    returns (ExchangeRateSnapshot memory);

  /**
   * @dev Sets the GHO debt token (only callable by SHORT_EXECUTOR)
   * @param newGHODebtToken Address to GHO debt token
   */
  function setGHODebtToken(IGhoVariableDebtTokenTransferHook newGHODebtToken)
    external;

  /**
   * @dev Claims an `amount` of `REWARD_TOKEN` and stakes.
   * @param to Address to stake to
   * @param amount Amount to claim
   */
  function claimRewardsAndStake(address to, uint256 amount)
    external
    returns (uint256);

  /**
   * @dev Claims an `amount` of `REWARD_TOKEN` and stakes. Only the claim helper contract is allowed to call this function
   * @param from The address of the from from which to claim
   * @param to Address to stake to
   * @param amount Amount to claim
   */
  function claimRewardsAndStakeOnBehalf(
    address from,
    address to,
    uint256 amount
  ) external returns (uint256);

  /**
   * @dev Allows staking a certain amount of STAKED_TOKEN with gasless approvals (permit)
   * @param from The address staking the token
   * @param amount The amount to be staked
   * @param deadline The permit execution deadline
   * @param v The v component of the signed message
   * @param r The r component of the signed message
   * @param s The s component of the signed message
   */
  function stakeWithPermit(
    address from,
    uint256 amount,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) external;
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

interface IStakedTokenV2 {
  struct CooldownSnapshot {
    uint40 timestamp;
    uint216 amount;
  }

  event RewardsAccrued(address user, uint256 amount);
  event RewardsClaimed(
    address indexed from,
    address indexed to,
    uint256 amount
  );
  event Cooldown(address indexed user, uint256 amount);

  /**
   * @dev Allows staking a specified amount of STAKED_TOKEN
   * @param to The address to receiving the shares
   * @param amount The amount of assets to be staked
   */
  function stake(address to, uint256 amount) external;

  /**
   * @dev Redeems shares, and stop earning rewards
   * @param to Address to redeem to
   * @param amount Amount of shares to redeem
   */
  function redeem(address to, uint256 amount) external;

  /**
   * @dev Activates the cooldown period to unstake
   * - It can't be called if the user is not staking
   */
  function cooldown() external;

  /**
   * @dev Claims an `amount` of `REWARD_TOKEN` to the address `to`
   * @param to Address to send the claimed rewards
   * @param amount Amount to stake
   */
  function claimRewards(address to, uint256 amount) external;

  /**
   * @dev Return the total rewards pending to claim by an staker
   * @param staker The staker address
   * @return The rewards
   */
  function getTotalRewardsBalance(address staker)
    external
    view
    returns (uint256);

  /**
   * @dev implements the permit function as for https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md
   * @param owner the owner of the funds
   * @param spender the spender
   * @param value the amount
   * @param deadline the deadline timestamp, type(uint256).max for no deadline
   * @param v signature param
   * @param s signature param
   * @param r signature param
   */
  function permit(
    address owner,
    address spender,
    uint256 value,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) external;
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {IStakedTokenV2} from './IStakedTokenV2.sol';

interface IStakedTokenV3 is IStakedTokenV2 {
  event Staked(
    address indexed from,
    address indexed to,
    uint256 assets,
    uint256 shares
  );
  event Redeem(
    address indexed from,
    address indexed to,
    uint256 assets,
    uint256 shares
  );
  event MaxSlashablePercentageChanged(uint256 newPercentage);
  event Slashed(address indexed destination, uint256 amount);
  event SlashingExitWindowDurationChanged(uint256 windowSeconds);
  event CooldownSecondsChanged(uint256 cooldownSeconds);
  event ExchangeRateChanged(uint216 exchangeRate);
  event FundsReturned(uint256 amount);
  event SlashingSettled();

  /**
   * @dev Returns the current exchange rate
   * @return exchangeRate as 18 decimal precision uint216
   */
  function getExchangeRate() external view returns (uint216);

  /**
   * @dev Executes a slashing of the underlying of a certain amount, transferring the seized funds
   * to destination. Decreasing the amount of underlying will automatically adjust the exchange rate.
   * A call to `slash` will start a slashing event which has to be settled via `settleSlashing`.
   * As long as the slashing event is ongoing, stake and slash are deactivated.
   * - MUST NOT be called when a previous slashing is still ongoing
   * @param destination the address where seized funds will be transferred
   * @param amount the amount to be slashed
   * - if the amount bigger than maximum allowed, the maximum will be slashed instead.
   * @return amount the amount slashed
   */
  function slash(address destination, uint256 amount)
    external
    returns (uint256);

  /**
   * @dev Settles an ongoing slashing event
   */
  function settleSlashing() external;

  /**
   * @dev Pulls STAKE_TOKEN and distributes them amongst current stakers by altering the exchange rate.
   * This method is permissionless and intended to be used after a slashing event to return potential excess funds.
   * @param amount amount of STAKE_TOKEN to pull.
   */
  function returnFunds(uint256 amount) external;

  /**
   * @dev Getter of the cooldown seconds
   * @return cooldownSeconds the amount of seconds between starting the cooldown and being able to redeem
   */
  function getCooldownSeconds() external view returns (uint256);

  /**
   * @dev Getter of the cooldown seconds
   * @return cooldownSeconds the amount of seconds between starting the cooldown and being able to redeem
   */
  function COOLDOWN_SECONDS() external view returns (uint256); // @deprecated

  /**
   * @dev Setter of cooldown seconds
   * Can only be called by the cooldown admin
   * @param cooldownSeconds the new amount of seconds you have to wait between starting the cooldown and being able to redeem
   */
  function setCooldownSeconds(uint256 cooldownSeconds) external;

  /**
   * @dev Getter of the max slashable percentage of the total staked amount.
   * @return percentage the maximum slashable percentage
   */
  function getMaxSlashablePercentage() external view returns (uint256);

  /**
   * @dev Setter of max slashable percentage of the total staked amount.
   * Can only be called by the slashing admin
   * @param percentage the new maximum slashable percentage
   */
  function setMaxSlashablePercentage(uint256 percentage) external;

  /**
   * @dev returns the exact amount of shares that would be received for the provided number of assets
   * @param assets the number of assets to stake
   * @return uint256 shares the number of shares that would be received
   */
  function previewStake(uint256 assets) external view returns (uint256);

  /**
   * @dev Activates the cooldown period to unstake
   * - It can't be called if the user is not staking
   */
  function cooldownOnBehalfOf(address from) external;

  /**
   * @dev Claims an `amount` of `REWARD_TOKEN` to the address `to` on behalf of the user. Only the claim helper contract is allowed to call this function
   * @param from The address of the user from to claim
   * @param to Address to send the claimed rewards
   * @param amount Amount to claim
   */
  function claimRewardsOnBehalf(
    address from,
    address to,
    uint256 amount
  ) external returns (uint256);

  /**
   * @dev returns the exact amount of assets that would be redeemed for the provided number of shares
   * @param shares the number of shares to redeem
   * @return uint256 assets the number of assets that would be redeemed
   */
  function previewRedeem(uint256 shares) external view returns (uint256);

  /**
   * @dev Redeems shares for a user. Only the claim helper contract is allowed to call this function
   * @param from Address to redeem from
   * @param to Address to redeem to
   * @param amount Amount of shares to redeem
   */
  function redeemOnBehalf(
    address from,
    address to,
    uint256 amount
  ) external;

  /**
   * @dev Claims an `amount` of `REWARD_TOKEN` and redeems to the provided address
   * @param to Address to claim and redeem to
   * @param claimAmount Amount to claim
   * @param redeemAmount Amount to redeem
   */
  function claimRewardsAndRedeem(
    address to,
    uint256 claimAmount,
    uint256 redeemAmount
  ) external;

  /**
   * @dev Claims an `amount` of `REWARD_TOKEN` and redeems the `redeemAmount` to an address. Only the claim helper contract is allowed to call this function
   * @param from The address of the from
   * @param to Address to claim and redeem to
   * @param claimAmount Amount to claim
   * @param redeemAmount Amount to redeem
   */
  function claimRewardsAndRedeemOnBehalf(
    address from,
    address to,
    uint256 claimAmount,
    uint256 redeemAmount
  ) external;
}

File 14 of 25 : ITransferHook.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

interface ITransferHook {
  function onTransfer(
    address from,
    address to,
    uint256 amount
  ) external;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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://consensys.net/diligence/blog/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 functionCallWithValue(target, data, 0, "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");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or 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 {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // 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);
        }
    }
}

// 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 25 : DistributionTypes.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;

library DistributionTypes {
    struct AssetConfigInput {
        uint128 emissionPerSecond;
        uint256 totalStaked;
        address underlyingAsset;
    }

    struct UserStakeInput {
        address underlyingAsset;
        uint256 stakedByUser;
        uint256 totalStaked;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

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

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

    uint256 internal _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals; // @deprecated
    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor() {}

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

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

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

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

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

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

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

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

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

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

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

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

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

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

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

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

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

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

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

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

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

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {ERC20} from './ERC20.sol';
import {
  IGovernancePowerDelegationToken
} from '../interfaces/IGovernancePowerDelegationToken.sol';

/**
 * @notice implementation of the AAVE token contract
 * @author Aave
 */
abstract contract GovernancePowerDelegationERC20 is ERC20, IGovernancePowerDelegationToken {
  /// @notice The EIP-712 typehash for the delegation struct used by the contract
  bytes32 public constant DELEGATE_BY_TYPE_TYPEHASH = keccak256(
    'DelegateByType(address delegatee,uint256 type,uint256 nonce,uint256 expiry)'
  );

  bytes32 public constant DELEGATE_TYPEHASH = keccak256(
    'Delegate(address delegatee,uint256 nonce,uint256 expiry)'
  );

  /// @dev snapshot of a value on a specific block, used for votes
  struct Snapshot {
    uint128 blockNumber;
    uint128 value;
  }

  /**
   * @dev delegates one specific power to a delegatee
   * @param delegatee the user which delegated power has changed
   * @param delegationType the type of delegation (VOTING_POWER, PROPOSITION_POWER)
   **/
  function delegateByType(address delegatee, DelegationType delegationType) external override {
    _delegateByType(msg.sender, delegatee, delegationType);
  }

  /**
   * @dev delegates all the powers to a specific user
   * @param delegatee the user to which the power will be delegated
   **/
  function delegate(address delegatee) external override {
    _delegateByType(msg.sender, delegatee, DelegationType.VOTING_POWER);
    _delegateByType(msg.sender, delegatee, DelegationType.PROPOSITION_POWER);
  }

  /**
   * @dev returns the delegatee of an user
   * @param delegator the address of the delegator
   **/
  function getDelegateeByType(address delegator, DelegationType delegationType)
    external
    override
    view
    returns (address)
  {
    (, , mapping(address => address) storage delegates) = _getDelegationDataByType(delegationType);

    return _getDelegatee(delegator, delegates);
  }

  /**
   * @dev returns the current delegated power of a user. The current power is the
   * power delegated at the time of the last snapshot
   * @param user the user
   **/
  function getPowerCurrent(address user, DelegationType delegationType)
    external
    override
    view
    returns (uint256)
  {
    (
      mapping(address => mapping(uint256 => Snapshot)) storage snapshots,
      mapping(address => uint256) storage snapshotsCounts,

    ) = _getDelegationDataByType(delegationType);

    return _searchByBlockNumber(snapshots, snapshotsCounts, user, block.number);
  }

  /**
   * @dev returns the delegated power of a user at a certain block
   * @param user the user
   **/
  function getPowerAtBlock(
    address user,
    uint256 blockNumber,
    DelegationType delegationType
  ) external override view returns (uint256) {
    (
      mapping(address => mapping(uint256 => Snapshot)) storage snapshots,
      mapping(address => uint256) storage snapshotsCounts,

    ) = _getDelegationDataByType(delegationType);

    return _searchByBlockNumber(snapshots, snapshotsCounts, user, blockNumber);
  }

  /**
   * @dev returns the total supply at a certain block number
   * used by the voting strategy contracts to calculate the total votes needed for threshold/quorum
   * In this initial implementation with no AAVE minting, simply returns the current supply
   * A snapshots mapping will need to be added in case a mint function is added to the AAVE token in the future
   **/
  function totalSupplyAt(uint256) external override view returns (uint256) {
    return super.totalSupply();
  }

  /**
   * @dev delegates the specific power to a delegatee
   * @param delegatee the user which delegated power has changed
   * @param delegationType the type of delegation (VOTING_POWER, PROPOSITION_POWER)
   **/
  function _delegateByType(
    address delegator,
    address delegatee,
    DelegationType delegationType
  ) internal {
    require(delegatee != address(0), 'INVALID_DELEGATEE');

    (, , mapping(address => address) storage delegates) = _getDelegationDataByType(delegationType);

    uint256 delegatorBalance = balanceOf(delegator);

    address previousDelegatee = _getDelegatee(delegator, delegates);

    delegates[delegator] = delegatee;

    _moveDelegatesByType(previousDelegatee, delegatee, delegatorBalance, delegationType);
    emit DelegateChanged(delegator, delegatee, delegationType);
  }

  /**
   * @dev moves delegated power from one user to another
   * @param from the user from which delegated power is moved
   * @param to the user that will receive the delegated power
   * @param amount the amount of delegated power to be moved
   * @param delegationType the type of delegation (VOTING_POWER, PROPOSITION_POWER)
   **/
  function _moveDelegatesByType(
    address from,
    address to,
    uint256 amount,
    DelegationType delegationType
  ) internal {
    if (from == to) {
      return;
    }

    (
      mapping(address => mapping(uint256 => Snapshot)) storage snapshots,
      mapping(address => uint256) storage snapshotsCounts,

    ) = _getDelegationDataByType(delegationType);

    if (from != address(0)) {
      uint256 previous = 0;
      uint256 fromSnapshotsCount = snapshotsCounts[from];

      if (fromSnapshotsCount != 0) {
        previous = snapshots[from][fromSnapshotsCount - 1].value;
      } else {
        previous = balanceOf(from);
      }

      _writeSnapshot(
        snapshots,
        snapshotsCounts,
        from,
        uint128(previous),
        uint128(previous - amount)
      );

      emit DelegatedPowerChanged(from, previous - amount, delegationType);
    }
    if (to != address(0)) {
      uint256 previous = 0;
      uint256 toSnapshotsCount = snapshotsCounts[to];
      if (toSnapshotsCount != 0) {
        previous = snapshots[to][toSnapshotsCount - 1].value;
      } else {
        previous = balanceOf(to);
      }

      _writeSnapshot(
        snapshots,
        snapshotsCounts,
        to,
        uint128(previous),
        uint128(previous + amount)
      );

      emit DelegatedPowerChanged(to, previous + amount, delegationType);
    }
  }

  /**
   * @dev searches a snapshot by block number. Uses binary search.
   * @param snapshots the snapshots mapping
   * @param snapshotsCounts the number of snapshots
   * @param user the user for which the snapshot is being searched
   * @param blockNumber the block number being searched
   **/
  function _searchByBlockNumber(
    mapping(address => mapping(uint256 => Snapshot)) storage snapshots,
    mapping(address => uint256) storage snapshotsCounts,
    address user,
    uint256 blockNumber
  ) internal virtual view returns (uint256) {
    require(blockNumber <= block.number, 'INVALID_BLOCK_NUMBER');

    uint256 snapshotsCount = snapshotsCounts[user];

    if (snapshotsCount == 0) {
      return balanceOf(user);
    }

    // Check implicit zero balance
    if (snapshots[user][0].blockNumber > blockNumber) {
      return 0;
    }

    return _binarySearch(snapshots[user], snapshotsCount, blockNumber);
  }

  function _binarySearch(mapping(uint256 => Snapshot) storage snapshots, uint256 snapshotsCount, uint256 blockNumber) internal view returns (uint256) {
    unchecked {
      // First check most recent balance
      if (snapshots[snapshotsCount - 1].blockNumber <= blockNumber) {
        return snapshots[snapshotsCount - 1].value;
      }

      uint256 lower = 0;
      uint256 upper = snapshotsCount - 1;
      while (upper > lower) {
        uint256 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
        Snapshot memory snapshot = snapshots[center];
        if (snapshot.blockNumber == blockNumber) {
          return snapshot.value;
        } else if (snapshot.blockNumber < blockNumber) {
          lower = center;
        } else {
          upper = center - 1;
        }
      }
      return snapshots[lower].value;
    }
  }

  /**
   * @dev returns the delegation data (snapshot, snapshotsCount, list of delegates) by delegation type
   * NOTE: Ideal implementation would have mapped this in a struct by delegation type. Unfortunately,
   * the AAVE token and StakeToken already include a mapping for the snapshots, so we require contracts
   * who inherit from this to provide access to the delegation data by overriding this method.
   * @param delegationType the type of delegation
   **/
  function _getDelegationDataByType(DelegationType delegationType)
    internal
    virtual
    view
    returns (
      mapping(address => mapping(uint256 => Snapshot)) storage, //snapshots
      mapping(address => uint256) storage, //snapshots count
      mapping(address => address) storage //delegatees list
    );

  /**
   * @dev Writes a snapshot for an owner of tokens
   * @param owner The owner of the tokens
   * @param oldValue The value before the operation that is gonna be executed after the snapshot
   * @param newValue The value after the operation
   */
  function _writeSnapshot(
    mapping(address => mapping(uint256 => Snapshot)) storage snapshots,
    mapping(address => uint256) storage snapshotsCounts,
    address owner,
    uint128 oldValue,
    uint128 newValue
  ) internal {
    uint128 currentBlock = uint128(block.number);

    uint256 ownerSnapshotsCount = snapshotsCounts[owner];
    mapping(uint256 => Snapshot) storage snapshotsOwner = snapshots[owner];

    // Doing multiple operations in the same block
    if (
      ownerSnapshotsCount != 0 &&
      snapshotsOwner[ownerSnapshotsCount - 1].blockNumber == currentBlock
    ) {
      snapshotsOwner[ownerSnapshotsCount - 1].value = newValue;
    } else {
      snapshotsOwner[ownerSnapshotsCount] = Snapshot(currentBlock, newValue);
      snapshotsCounts[owner] = ownerSnapshotsCount + 1;
    }
  }

  /**
   * @dev returns the user delegatee. If a user never performed any delegation,
   * his delegated address will be 0x0. In that case we simply return the user itself
   * @param delegator the address of the user for which return the delegatee
   * @param delegates the array of delegates for a particular type of delegation
   **/
  function _getDelegatee(address delegator, mapping(address => address) storage delegates)
    internal
    view
    returns (address)
  {
    address previousDelegatee = delegates[delegator];

    if (previousDelegatee == address(0)) {
      return delegator;
    }

    return previousDelegatee;
  }
}

File 20 of 25 : GovernancePowerWithSnapshot.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

import {ERC20} from '../lib/ERC20.sol';
import {ITransferHook} from '../interfaces/ITransferHook.sol';
import {
  GovernancePowerDelegationERC20
} from './GovernancePowerDelegationERC20.sol';

/**
 * @title ERC20WithSnapshot
 * @notice ERC20 including snapshots of balances on transfer-related actions
 * @author Aave
 **/
abstract contract GovernancePowerWithSnapshot is GovernancePowerDelegationERC20 {
  /**
   * @dev The following storage layout points to the prior StakedToken.sol implementation:
   * _snapshots => _votingSnapshots
   * _snapshotsCounts =>  _votingSnapshotsCounts
   * _aaveGovernance => _aaveGovernance
   */
  mapping(address => mapping(uint256 => Snapshot)) public _votingSnapshots;
  mapping(address => uint256) public _votingSnapshotsCounts;

  /// @dev reference to the Aave governance contract to call (if initialized) on _beforeTokenTransfer
  /// !!! IMPORTANT The Aave governance is considered a trustable contract, being its responsibility
  /// to control all potential reentrancies by calling back the this contract
  /// @dev DEPRECATED
  ITransferHook public _aaveGovernance;
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

/**
 * @title PercentageMath library
 * @author Aave
 * @notice Provides functions to perform percentage calculations
 * @dev Percentages are defined by default with 2 decimals of precision (100.00). The precision is indicated by PERCENTAGE_FACTOR
 * @dev Operations are rounded half up
 **/

library PercentageMath {
    uint256 constant PERCENTAGE_FACTOR = 1e4; //percentage plus two decimals
    uint256 constant HALF_PERCENT = PERCENTAGE_FACTOR / 2;

    /**
     * @dev Executes a percentage multiplication
     * @param value The value of which the percentage needs to be calculated
     * @param percentage The percentage of the value to be calculated
     * @return The percentage of value
     **/
    function percentMul(uint256 value, uint256 percentage)
        internal
        pure
        returns (uint256)
    {
        if (value == 0 || percentage == 0) {
            return 0;
        }

        require(
            value <= (type(uint256).max) / percentage,
            "MATH_MULTIPLICATION_OVERFLOW"
        );

        return (value * percentage) / PERCENTAGE_FACTOR;
    }

    /**
     * @dev Executes a percentage division
     * @param value The value of which the percentage needs to be calculated
     * @param percentage The percentage of the value to be calculated
     * @return The value divided the percentage
     **/
    function percentDiv(uint256 value, uint256 percentage)
        internal
        pure
        returns (uint256)
    {
        require(percentage != 0, "MATH_DIVISION_BY_ZERO");

        require(
            value <= type(uint256).max / PERCENTAGE_FACTOR,
            "MATH_MULTIPLICATION_OVERFLOW"
        );

        return (value * PERCENTAGE_FACTOR) / percentage;
    }
}

File 22 of 25 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(value);
    }

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

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

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

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

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

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

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

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

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../interfaces/IERC20.sol";
import "./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
                )
            );
        }
    }

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

pragma solidity ^0.8.0;

/**
 * @title RoleManager
 * @notice Generic role manager to manage slashing and cooldown admin in StakedAaveV3.
 *         It implements a claim admin role pattern to safely migrate between different admin addresses
 * @author Aave
 **/
contract RoleManager {
  struct InitAdmin {
    uint256 role;
    address admin;
  }

  mapping(uint256 => address) private _admins;
  mapping(uint256 => address) private _pendingAdmins;

  event PendingAdminChanged(address indexed newPendingAdmin, uint256 role);
  event RoleClaimed(address indexed newAdmin, uint256 role);

  modifier onlyRoleAdmin(uint256 role) {
    require(_admins[role] == msg.sender, 'CALLER_NOT_ROLE_ADMIN');
    _;
  }

  modifier onlyPendingRoleAdmin(uint256 role) {
    require(
      _pendingAdmins[role] == msg.sender,
      'CALLER_NOT_PENDING_ROLE_ADMIN'
    );
    _;
  }

  /**
   * @dev returns the admin associated with the specific role
   * @param role the role associated with the admin being returned
   **/
  function getAdmin(uint256 role) public view returns (address) {
    return _admins[role];
  }

  /**
   * @dev returns the pending admin associated with the specific role
   * @param role the role associated with the pending admin being returned
   **/
  function getPendingAdmin(uint256 role) public view returns (address) {
    return _pendingAdmins[role];
  }

  /**
   * @dev sets the pending admin for a specific role
   * @param role the role associated with the new pending admin being set
   * @param newPendingAdmin the address of the new pending admin
   **/
  function setPendingAdmin(uint256 role, address newPendingAdmin)
    public
    onlyRoleAdmin(role)
  {
    _pendingAdmins[role] = newPendingAdmin;
    emit PendingAdminChanged(newPendingAdmin, role);
  }

  /**
   * @dev allows the caller to become a specific role admin
   * @param role the role associated with the admin claiming the new role
   **/
  function claimRoleAdmin(uint256 role) external onlyPendingRoleAdmin(role) {
    _admins[role] = msg.sender;
    _pendingAdmins[role] = address(0);
    emit RoleClaimed(msg.sender, role);
  }

  function _initAdmins(InitAdmin[] memory initAdmins) internal {
    for (uint256 i = 0; i < initAdmins.length; i++) {
      require(
        _admins[initAdmins[i].role] == address(0) &&
          initAdmins[i].admin != address(0),
        'ADMIN_CANNOT_BE_INITIALIZED'
      );
      _admins[initAdmins[i].role] = initAdmins[i].admin;
      emit RoleClaimed(initAdmins[i].admin, initAdmins[i].role);
    }
  }
}

File 25 of 25 : VersionedInitializable.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.8.0;

/**
 * @title VersionedInitializable
 *
 * @dev Helper contract to support initializer functions. To use it, replace
 * the constructor with a function that has the `initializer` modifier.
 * WARNING: Unlike constructors, initializer functions must be manually
 * invoked. This applies both to deploying an Initializable contract, as well
 * as extending an Initializable contract via inheritance.
 * WARNING: When used with inheritance, manual care must be taken to not invoke
 * a parent initializer twice, or ensure that all initializers are idempotent,
 * because this is not dealt with automatically as with constructors.
 *
 * @author Aave, inspired by the OpenZeppelin Initializable contract
 */
abstract contract VersionedInitializable {
  /**
   * @dev Indicates that the contract has been initialized.
   */
  uint256 internal lastInitializedRevision = 0;

  /**
   * @dev Modifier to use in the initializer function of a contract.
   */
  modifier initializer() {
    uint256 revision = getRevision();
    require(
      revision > lastInitializedRevision,
      'Contract instance has already been initialized'
    );

    lastInitializedRevision = revision;

    _;
  }

  /// @dev returns the revision number of the contract.
  /// Needs to be defined in the inherited class as a constant.
  function getRevision() internal pure virtual returns (uint256);

  // Reserved storage space to allow for layout changes in the future.
  uint256[50] private ______gap;
}

Settings
{
  "remappings": [
    "@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core/",
    "@aave/periphery-v3/=lib/aave-address-book/lib/aave-v3-periphery/",
    "aave-address-book/=lib/aave-address-book/src/",
    "aave-helpers/=lib/aave-helpers/src/",
    "aave-v3-core/=lib/aave-address-book/lib/aave-v3-core/",
    "aave-v3-periphery/=lib/aave-address-book/lib/aave-v3-periphery/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "governance-crosschain-bridges/=lib/aave-helpers/lib/governance-crosschain-bridges/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "solidity-utils/=lib/aave-helpers/lib/solidity-utils/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract IERC20","name":"stakedToken","type":"address"},{"internalType":"contract IERC20","name":"rewardToken","type":"address"},{"internalType":"uint256","name":"unstakeWindow","type":"uint256"},{"internalType":"address","name":"rewardsVault","type":"address"},{"internalType":"address","name":"emissionManager","type":"address"},{"internalType":"uint128","name":"distributionDuration","type":"uint128"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"emission","type":"uint256"}],"name":"AssetConfigUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"AssetIndexUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Cooldown","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"cooldownSeconds","type":"uint256"}],"name":"CooldownSecondsChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"delegatee","type":"address"},{"indexed":false,"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"DelegateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"DelegatedPowerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint216","name":"exchangeRate","type":"uint216"}],"name":"ExchangeRateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FundsReturned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newDebtToken","type":"address"}],"name":"GHODebtTokenChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newPercentage","type":"uint256"}],"name":"MaxSlashablePercentageChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newPendingAdmin","type":"address"},{"indexed":false,"internalType":"uint256","name":"role","type":"uint256"}],"name":"PendingAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsAccrued","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAdmin","type":"address"},{"indexed":false,"internalType":"uint256","name":"role","type":"uint256"}],"name":"RoleClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"destination","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Slashed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"windowSeconds","type":"uint256"}],"name":"SlashingExitWindowDurationChanged","type":"event"},{"anonymous":false,"inputs":[],"name":"SlashingSettled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"UserIndexUpdated","type":"event"},{"inputs":[],"name":"CLAIM_HELPER_ROLE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"COOLDOWN_ADMIN_ROLE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"COOLDOWN_SECONDS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DELEGATE_BY_TYPE_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DELEGATE_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DISTRIBUTION_END","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EIP712_REVISION","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EMISSION_MANAGER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EXCHANGE_RATE_UNIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"INITIAL_EXCHANGE_RATE","outputs":[{"internalType":"uint216","name":"","type":"uint216"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LOWER_BOUND","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRECISION","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REVISION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"REWARDS_VAULT","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REWARD_TOKEN","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SLASH_ADMIN_ROLE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STAKED_TOKEN","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNSTAKE_WINDOW","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_aaveGovernance","outputs":[{"internalType":"contract ITransferHook","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"_votingSnapshots","outputs":[{"internalType":"uint128","name":"blockNumber","type":"uint128"},{"internalType":"uint128","name":"value","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_votingSnapshotsCounts","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"assets","outputs":[{"internalType":"uint128","name":"emissionPerSecond","type":"uint128"},{"internalType":"uint128","name":"lastUpdateTimestamp","type":"uint128"},{"internalType":"uint256","name":"index","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"claimAmount","type":"uint256"},{"internalType":"uint256","name":"redeemAmount","type":"uint256"}],"name":"claimRewardsAndRedeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"claimAmount","type":"uint256"},{"internalType":"uint256","name":"redeemAmount","type":"uint256"}],"name":"claimRewardsAndRedeemOnBehalf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"claimRewardsAndStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"claimRewardsAndStakeOnBehalf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"claimRewardsOnBehalf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"role","type":"uint256"}],"name":"claimRoleAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint128","name":"emissionPerSecond","type":"uint128"},{"internalType":"uint256","name":"totalStaked","type":"uint256"},{"internalType":"address","name":"underlyingAsset","type":"address"}],"internalType":"struct DistributionTypes.AssetConfigInput[]","name":"assetsConfigInput","type":"tuple[]"}],"name":"configureAssets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cooldown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"}],"name":"cooldownOnBehalfOf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"}],"name":"delegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"delegateBySig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"delegateByType","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"delegateByTypeBySig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"role","type":"uint256"}],"name":"getAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCooldownSeconds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegator","type":"address"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"getDelegateeByType","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getExchangeRate","outputs":[{"internalType":"uint216","name":"","type":"uint216"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"index","type":"uint32"}],"name":"getExchangeRateSnapshot","outputs":[{"components":[{"internalType":"uint40","name":"blockNumber","type":"uint40"},{"internalType":"uint216","name":"value","type":"uint216"}],"internalType":"struct IStakedAaveV3.ExchangeRateSnapshot","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getExchangeRateSnapshotsCount","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxSlashablePercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"role","type":"uint256"}],"name":"getPendingAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"getPowerAtBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"enum IGovernancePowerDelegationToken.DelegationType","name":"delegationType","type":"uint8"}],"name":"getPowerCurrent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"staker","type":"address"}],"name":"getTotalRewardsBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"asset","type":"address"}],"name":"getUserAssetData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ghoDebtToken","outputs":[{"internalType":"contract IGhoVariableDebtTokenTransferHook","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"inPostSlashingPeriod","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"slashingAdmin","type":"address"},{"internalType":"address","name":"cooldownPauseAdmin","type":"address"},{"internalType":"address","name":"claimHelper","type":"address"},{"internalType":"uint256","name":"maxSlashablePercentage","type":"uint256"},{"internalType":"uint256","name":"cooldownSeconds","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeemOnBehalf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"returnFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"cooldownSeconds","type":"uint256"}],"name":"setCooldownSeconds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IGhoVariableDebtTokenTransferHook","name":"newGHODebtToken","type":"address"}],"name":"setGHODebtToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"percentage","type":"uint256"}],"name":"setMaxSlashablePercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"role","type":"uint256"},{"internalType":"address","name":"newPendingAdmin","type":"address"}],"name":"setPendingAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"settleSlashing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"destination","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"slash","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"stakeWithPermit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"stakerRewardsToClaim","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"stakersCooldowns","outputs":[{"internalType":"uint40","name":"timestamp","type":"uint40"},{"internalType":"uint216","name":"amount","type":"uint216"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"totalSupplyAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]

61016060405260006009553480156200001757600080fd5b5060405162005687380380620056878339810160408190526200003a916200014c565b858585858585858585858585816001600160801b0382166200005d8142620001f5565b608052506001600160a01b0390811660a05295861660c052505091831660e05261010052166101205260056009819055506000866001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015620000cf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000f5919062000211565b60ff1690506200010781600a6200033a565b61014052506200011e9550506200012e9350505050565b6009555062000348945050505050565b600590565b6001600160a01b03811681146200014957600080fd5b50565b60008060008060008060c087890312156200016657600080fd5b8651620001738162000133565b6020880151909650620001868162000133565b604088015160608901519196509450620001a08162000133565b6080880151909350620001b38162000133565b60a08801519092506001600160801b0381168114620001d157600080fd5b809150509295509295509295565b634e487b7160e01b600052601160045260246000fd5b808201808211156200020b576200020b620001df565b92915050565b6000602082840312156200022457600080fd5b815160ff811681146200023657600080fd5b9392505050565b600181815b808511156200027e578160001904821115620002625762000262620001df565b808516156200027057918102915b93841c939080029062000242565b509250929050565b60008262000297575060016200020b565b81620002a6575060006200020b565b8160018114620002bf5760028114620002ca57620002ea565b60019150506200020b565b60ff841115620002de57620002de620001df565b50506001821b6200020b565b5060208310610133831016604e8410600b84101617156200030f575081810a6200020b565b6200031b83836200023d565b8060001904821115620003325762000332620001df565b029392505050565b600062000236838362000286565b60805160a05160c05160e051610100516101205161014051615266620004216000396000818161083601528181610e3a0152818161115701526111c8015260008181610a18015261288a0152600081816106a40152612525015260008181610a6d0152818161286801526130da01526000818161062a01528181610ee30152818161125a01528181611411015281816117ba0152818161274701528181612e5c01526130b0015260008181610bea01526119910152600081816109f101528181613e7001528181613eac0152613ed901526152666000f3fe608060405234801561001057600080fd5b50600436106104965760003560e01c80638c9a281d11610262578063aff05aa911610151578063dbc0ed8a116100ce578063eab5231811610092578063eab5231814610c65578063f036bc6814610c78578063f11b818814610c8c578063f34d96da14610cee578063f713d8a814610cf6578063fde9eb6914610d0957600080fd5b8063dbc0ed8a14610c1f578063dc937e1c14610c27578063dd62ed3e14610c3a578063dde43cba14610c4d578063e6aa216c14610c5457600080fd5b8063c2ffbb9111610115578063c2ffbb9114610bac578063c3863ada14610bbf578063c3cda52014610bd2578063cbcbb50714610be5578063d505accf14610c0c57600080fd5b8063aff05aa914610b4b578063b2a5dbfa14610b53578063b2f4201d14610b66578063b9844d8d14610b79578063c18f539a14610b9957600080fd5b80639a99b4f0116101df578063a9059cbb116101a3578063a9059cbb14610ae3578063aa9fbe0214610af6578063aaf5eb6814610b1d578063ab406fe614610b25578063adc9772e14610b3857600080fd5b80639a99b4f014610a8f5780639c9b515414610aa25780639e3ffce014610ab5578063a457c2d714610abd578063a6b63eb814610ad057600080fd5b8063946776cd11610226578063946776cd14610a13578063955e18af14610a3a57806395d89b4114610a4d578063981b24d014610a5557806399248ea714610a6857600080fd5b80638c9a281d146109325780638dbefee21461093a5780638e9b2ca41461094d5780638ef98e0e1461095c578063919cd40f146109ec57600080fd5b806345755dd6116103895780636f50458d1161030657806374011f56116102ca57806374011f56146108a457806378160376146108b7578063787a08a6146108d75780637b5b1157146108df5780637bb73c97146108f25780637e90d7ef1461091257600080fd5b80636f50458d1461085857806370a082311461086b578063727a5d571461087e57806372b49d631461082957806373d6a8891461089157600080fd5b80635b3cc0cf1161034d5780635b3cc0cf146107925780635c19a95c146107f157806360ba192b14610804578063616e0bf9146108295780636198e1351461083157600080fd5b806345755dd6146107095780634575e69b1461071c5780634998fffd146107455780634cdad5061461075857806358146d171461076b57600080fd5b806323b872dd116104175780633373ee4c116103db5780633373ee4c14610661578063359c4a961461069f5780633644e515146106c657806339509351146106cf57806341cbf54a146106e257600080fd5b806323b872dd146105d8578063250201db146105eb57806330adf81f146105fe578063312f6b8314610625578063313ce5671461064c57600080fd5b8063112d037c1161045e578063112d037c14610582578063174ed5421461059757806318160ddd146105aa5780631e9a6950146105b257806320fb80b5146105c557600080fd5b806302fb4d851461049b57806306fdde03146104c1578063091030c3146104d6578063095ea7b314610534578063111fd88b14610557575b600080fd5b6104ae6104a9366004614928565b610d1c565b6040519081526020015b60405180910390f35b6104c9610f5a565b6040516104b891906149a4565b61050f6104e43660046149b7565b603e6020526000908152604090205464ffffffffff811690600160281b90046001600160d81b031682565b6040805164ffffffffff90931683526001600160d81b039091166020830152016104b8565b610547610542366004614928565b610fec565b60405190151581526020016104b8565b61056a6105653660046149d4565b611004565b6040516001600160a01b0390911681526020016104b8565b6105956105903660046149ed565b61101f565b005b60535461056a906001600160a01b031681565b6002546104ae565b6105956105c0366004614928565b611069565b6104ae6105d33660046149ed565b611078565b6105476105e63660046149ed565b6110c9565b6105956105f93660046149b7565b6110ed565b6104ae7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b61056a7f000000000000000000000000000000000000000000000000000000000000000081565b60125b60405160ff90911681526020016104b8565b6104ae61066f366004614a2e565b6001600160a01b038082166000908152603c60209081526040808320938616835260029093019052205492915050565b6104ae7f000000000000000000000000000000000000000000000000000000000000000081565b6104ae60435481565b6105476106dd366004614928565b611133565b6104ae7f9a9a49b990ba9bb39f8048c490a40ab25c18f55d208d5fbcf958261a9b48716d81565b6105956107173660046149d4565b611155565b61056a61072a3660046149d4565b6000908152604660205260409020546001600160a01b031690565b6105956107533660046149b7565b6112ba565b6104ae6107663660046149d4565b611324565b61077a670de0b6b3a764000081565b6040516001600160d81b0390911681526020016104b8565b6107d16107a0366004614928565b60066020908152600092835260408084209091529082529020546001600160801b0380821691600160801b90041682565b604080516001600160801b039384168152929091166020830152016104b8565b6105956107ff3660046149b7565b61134f565b605154600160e01b900463ffffffff1660405163ffffffff90911681526020016104b8565b604f546104ae565b6104ae7f000000000000000000000000000000000000000000000000000000000000000081565b61056a610866366004614a7b565b611367565b6104ae6108793660046149b7565b611389565b6104ae61088c3660046149d4565b6113a4565b61059561089f366004614ac1565b6113c7565b6105956108b23660046149d4565b611480565b6104c9604051806040016040528060018152602001603160f81b81525081565b6105956114c3565b6105956108ed3660046149d4565b6114ce565b6104ae6109003660046149b7565b60076020526000908152604090205481565b6104ae6109203660046149b7565b603d6020526000908152604090205481565b6104ae600081565b6104ae6109483660046149b7565b611541565b6104ae670de0b6b3a764000081565b6109c161096a366004614b1b565b60408051808201909152600080825260208201525063ffffffff1660009081526052602090815260409182902082518084019093525464ffffffffff81168352600160281b90046001600160d81b03169082015290565b60408051825164ffffffffff1681526020928301516001600160d81b031692810192909252016104b8565b6104ae7f000000000000000000000000000000000000000000000000000000000000000081565b61056a7f000000000000000000000000000000000000000000000000000000000000000081565b6104ae610a48366004614928565b61161c565b6104c9611629565b6104ae610a633660046149d4565b611638565b61056a7f000000000000000000000000000000000000000000000000000000000000000081565b610595610a9d366004614928565b611643565b610595610ab0366004614b41565b61164e565b6104ae600181565b610547610acb366004614928565b6116a5565b610595610ade366004614b87565b611720565b610547610af1366004614928565b611838565b6104ae7f10d8d059343739efce7dad10d09f0806da52b252b3e6a7951920d2d6ec4102e581565b61064f601281565b610595610b33366004614be2565b611846565b610595610b46366004614928565b611909565b610595611914565b610595610b61366004614c77565b611986565b6104ae610b74366004614a7b565b611a41565b6104ae610b873660046149b7565b60446020526000908152604090205481565b6104ae610ba73660046149ed565b611a69565b6104ae610bba366004614d5e565b611ab0565b60085461056a906001600160a01b031681565b610595610be0366004614ac1565b611ad9565b61056a7f000000000000000000000000000000000000000000000000000000000000000081565b610595610c1a366004614d9c565b611c9e565b6104ae600281565b610595610c35366004614a7b565b611e66565b6104ae610c48366004614a2e565b611e71565b60056104ae565b6051546001600160d81b031661077a565b610595610c73366004614e0a565b611e9c565b60515461054790600160d81b900460ff1681565b610cc8610c9a3660046149b7565b603c60205260009081526040902080546001909101546001600160801b0380831692600160801b9004169083565b604080516001600160801b039485168152939092166020840152908201526060016104b8565b6050546104ae565b610595610d04366004614e3f565b611eb3565b610595610d173660046149d4565b612087565b6000610d286000611004565b6001600160a01b0316336001600160a01b031614610d615760405162461bcd60e51b8152600401610d5890614e73565b60405180910390fd5b605154600160d81b900460ff1615610dbb5760405162461bcd60e51b815260206004820152601d60248201527f50524556494f55535f534c415348494e475f4e4f545f534554544c45440000006044820152606401610d58565b60008211610df95760405162461bcd60e51b815260206004820152600b60248201526a16915493d7d05353d5539560aa1b6044820152606401610d58565b6000610e0460025490565b90506000610e1182611324565b90506000610e2a6050548361215890919063ffffffff16565b905080851115610e38578094505b7f0000000000000000000000000000000000000000000000000000000000000000610e638684614ec0565b1015610ea85760405162461bcd60e51b815260206004820152601460248201527352454d41494e494e475f4c545f4d494e494d554d60601b6044820152606401610d58565b6051805460ff60d81b1916600160d81b179055610ed6610ed1610ecb8785614ec0565b856121e4565b612222565b610f0a6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001687876122c7565b856001600160a01b03167f4ed05e9673c26d2ed44f7ef6a7f2942df0ee3b5e1e17db4b99f9dcd261a339cd86604051610f4591815260200190565b60405180910390a28493505050505b92915050565b606060038054610f6990614ed3565b80601f0160208091040260200160405190810160405280929190818152602001828054610f9590614ed3565b8015610fe25780601f10610fb757610100808354040283529160200191610fe2565b820191906000526020600020905b815481529060010190602001808311610fc557829003601f168201915b5050505050905090565b600033610ffa81858561232a565b5060019392505050565b6000908152604560205260409020546001600160a01b031690565b6110296002611004565b6001600160a01b0316336001600160a01b0316146110595760405162461bcd60e51b8152600401610d5890614f0d565b61106483838361244e565b505050565b61107433838361244e565b5050565b60006110846002611004565b6001600160a01b0316336001600160a01b0316146110b45760405162461bcd60e51b8152600401610d5890614f0d565b6110bf8484846127ce565b90505b9392505050565b6000336110d7858285612906565b6110e285858561297a565b506001949350505050565b6110f76002611004565b6001600160a01b0316336001600160a01b0316146111275760405162461bcd60e51b8152600401610d5890614f0d565b61113081612aa9565b50565b600033610ffa8185856111468383611e71565b6111509190614f44565b61232a565b7f00000000000000000000000000000000000000000000000000000000000000008110156111b95760405162461bcd60e51b8152602060048201526011602482015270414d4f554e545f4c545f4d494e494d554d60781b6044820152606401610d58565b60006111c460025490565b90507f000000000000000000000000000000000000000000000000000000000000000081101561122a5760405162461bcd60e51b81526020600482015260116024820152705348415245535f4c545f4d494e494d554d60781b6044820152606401610d58565b600061123582611324565b905061124d610ed16112478584614f44565b846121e4565b6112826001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333086612b8c565b6040518381527f278e51d3323fbf18b9fb8df3f8b97e31b145bc1146c52e764cf4aa1bfc4ba17d9060200160405180910390a1505050565b73ee56e2b3d491590b5b31738cc34d5232f378a8d533146112da57600080fd5b605380546001600160a01b0319166001600160a01b0383169081179091556040517f62bbced765bccc9ed93d0bae1b2a8c86e13b4663f8bf27d5936d9d619194c8a990600090a250565b6051546000906001600160d81b031661134583670de0b6b3a7640000614f57565b610f549190614f6e565b61135b33826000612bc4565b61113033826001612bc4565b60008061137383612cc5565b925050506113818482612d04565b949350505050565b6001600160a01b031660009081526020819052604090205490565b605154600090670de0b6b3a764000090611345906001600160d81b031684614f57565b60405163d505accf60e01b81526001600160a01b038781166004830152306024830152604482018790526064820186905260ff8516608483015260a4820184905260c482018390527f0000000000000000000000000000000000000000000000000000000000000000169063d505accf9060e401600060405180830381600087803b15801561145557600080fd5b505af1158015611469573d6000803e3d6000fd5b50505050611478868787612d2f565b505050505050565b61148a6000611004565b6001600160a01b0316336001600160a01b0316146114ba5760405162461bcd60e51b8152600401610d5890614e73565b61113081612edc565b6114cc33612aa9565b565b6114d86001611004565b6001600160a01b0316336001600160a01b0316146115385760405162461bcd60e51b815260206004820152601960248201527f43414c4c45525f4e4f545f434f4f4c444f574e5f41444d494e000000000000006044820152606401610d58565b61113081612f69565b604080516001808252818301909252600091829190816020015b611588604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b81526020019060019003908161155b5790505090506040518060600160405280306001600160a01b031681526020016115c085611389565b81526020016115ce60025490565b815250816000815181106115e4576115e4614f90565b60200260200101819052506115f98382612f9e565b6001600160a01b0384166000908152603d60205260409020546110c29190614f44565b60006110c23384846130ac565b606060048054610f6990614ed3565b6000610f5460025490565b6110643383836127ce565b6116586002611004565b6001600160a01b0316336001600160a01b0316146116885760405162461bcd60e51b8152600401610d5890614f0d565b6116938484846127ce565b5061169f84848361244e565b50505050565b600033816116b38286611e71565b9050838110156117135760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610d58565b6110e2828686840361232a565b600954600590811161178b5760405162461bcd60e51b815260206004820152602e60248201527f436f6e747261637420696e7374616e63652068617320616c726561647920626560448201526d195b881a5b9a5d1a585b1a5e995960921b6064820152608401610d58565b600981905561179d8686868686613197565b60405163095ea7b360e01b815230600482015260001960248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063095ea7b3906044016020604051808303816000875af115801561180b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182f9190614fa6565b50505050505050565b600033610ffa81858561297a565b60008281526045602052604090205482906001600160a01b031633146118a65760405162461bcd60e51b815260206004820152601560248201527421a0a62622a92fa727aa2fa927a622afa0a226a4a760591b6044820152606401610d58565b60008381526046602090815260409182902080546001600160a01b0319166001600160a01b03861690811790915591518581527fc3d1bf52795a20771ee6de3e59948fd83e10db956122d4709a3b86c512963855910160405180910390a2505050565b611074338383612d2f565b61191e6000611004565b6001600160a01b0316336001600160a01b03161461194e5760405162461bcd60e51b8152600401610d5890614e73565b6051805460ff60d81b191690556040517fcdee157e87ba915be681d4fa3f3d511afe7348eca06448a3accd6ac227fa40af90600090a1565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146119f65760405162461bcd60e51b815260206004820152601560248201527427a7262cafa2a6a4a9a9a4a7a72fa6a0a720a3a2a960591b6044820152606401610d58565b60005b8151811015611a3757600254828281518110611a1757611a17614f90565b602090810291909101810151015280611a2f81614fc8565b9150506119f9565b50611130816132bb565b6000806000611a4f84612cc5565b5091509150611a6082828743613429565b95945050505050565b6000611a756002611004565b6001600160a01b0316336001600160a01b031614611aa55760405162461bcd60e51b8152600401610d5890614f0d565b6110bf8484846130ac565b6000806000611abe84612cc5565b5091509150611acf82828888613429565b9695505050505050565b604080517f9a9a49b990ba9bb39f8048c490a40ab25c18f55d208d5fbcf958261a9b48716d60208201526001600160a01b03881691810191909152606081018690526080810185905260009060a001604051602081830303815290604052805190602001209050600060435482604051602001611b57929190614fe1565b60408051601f198184030181528282528051602091820120600080855291840180845281905260ff89169284019290925260608301879052608083018690529092509060019060a0016020604051602081039080840390855afa158015611bc2573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611bf55760405162461bcd60e51b8152600401610d5890614ffc565b6001600160a01b0381166000908152604460205260408120805491611c1983614fc8565b919050558814611c5b5760405162461bcd60e51b815260206004820152600d60248201526c494e56414c49445f4e4f4e434560981b6044820152606401610d58565b86421115611c7b5760405162461bcd60e51b8152600401610d5890615027565b611c87818a6000612bc4565b611c93818a6001612bc4565b505050505050505050565b6001600160a01b038716611ce45760405162461bcd60e51b815260206004820152600d60248201526c24a72b20a624a22fa7aba722a960991b6044820152606401610d58565b83421115611d045760405162461bcd60e51b8152600401610d5890615027565b6001600160a01b0387811660008181526044602090815260408083205460435482517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958c166060860152608085018b905260a0850181905260c08086018b90528251808703909101815260e086019092528151919092012090939192611d9b92919061010001614fe1565b60408051601f1981840301815282825280516020918201206000845290830180835281905260ff8816918301919091526060820186905260808201859052915060019060a0016020604051602081039080840390855afa158015611e03573d6000803e3d6000fd5b505050602060405103516001600160a01b0316896001600160a01b031614611e3d5760405162461bcd60e51b8152600401610d5890614ffc565b6001600160a01b0389166000908152604460205260409020600183019055611c9389898961232a565b611074338383612bc4565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b611ea73384846127ce565b5061106433848361244e565b60007f10d8d059343739efce7dad10d09f0806da52b252b3e6a7951920d2d6ec4102e588886001811115611ee957611ee9615053565b6040805160208101949094526001600160a01b039092169183019190915260608201526080810187905260a0810186905260c001604051602081830303815290604052805190602001209050600060435482604051602001611f4c929190614fe1565b60408051601f198184030181528282528051602091820120600080855291840180845281905260ff89169284019290925260608301879052608083018690529092509060019060a0016020604051602081039080840390855afa158015611fb7573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611fea5760405162461bcd60e51b8152600401610d5890614ffc565b6001600160a01b038116600090815260446020526040812080549161200e83614fc8565b9190505588146120505760405162461bcd60e51b815260206004820152600d60248201526c494e56414c49445f4e4f4e434560981b6044820152606401610d58565b864211156120705760405162461bcd60e51b8152600401610d5890615027565b61207b818b8b612bc4565b50505050505050505050565b60008181526046602052604090205481906001600160a01b031633146120ef5760405162461bcd60e51b815260206004820152601d60248201527f43414c4c45525f4e4f545f50454e44494e475f524f4c455f41444d494e0000006044820152606401610d58565b60008281526045602090815260408083208054336001600160a01b0319918216811790925560468452938290208054909416909355518481527f83a9ddad961dcb7c6894c9585a16ff7792c2ec8281256a3cc7303ae830152dcf91015b60405180910390a25050565b6000821580612165575081155b1561217257506000610f54565b61217e82600019614f6e565b8311156121cd5760405162461bcd60e51b815260206004820152601c60248201527f4d4154485f4d554c5449504c49434154494f4e5f4f564552464c4f57000000006044820152606401610d58565b6127106121da8385614f57565b6110c29190614f6e565b60006110c2836001816121ff670de0b6b3a764000087614f57565b6122099190614f44565b6122139190614ec0565b61221d9190614f6e565b613472565b6040518060400160405280612236436134df565b64ffffffffff90811682526001600160d81b038085166020938401526051805463ffffffff600160e01b9182900481166000908152605287526040902087519790960151909316600160281b0295909316949094179092558254601c926122a09290910416615069565b91906101000a81548163ffffffff021916908363ffffffff16021790555061113081613545565b6040516001600160a01b03831660248201526044810182905261106490849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526135e1565b6001600160a01b03831661238c5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610d58565b6001600160a01b0382166123ed5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610d58565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b8060000361246e5760405162461bcd60e51b8152600401610d589061508c565b6001600160a01b0383166000908152603e602090815260409182902082518084019093525464ffffffffff81168352600160281b90046001600160d81b031690820152605154600160d81b900460ff166125ad57604f5481516124d8919064ffffffffff16614f44565b421161251e5760405162461bcd60e51b815260206004820152601560248201527424a729aaa32324a1a4a2a72a2fa1a7a7a62227aba760591b6044820152606401610d58565b604f5481517f0000000000000000000000000000000000000000000000000000000000000000916125559164ffffffffff16614f44565b61255f9042614ec0565b11156125ad5760405162461bcd60e51b815260206004820152601760248201527f554e5354414b455f57494e444f575f46494e49534845440000000000000000006044820152606401610d58565b60006125b885611389565b605154909150600090600160d81b900460ff166125e25782602001516001600160d81b03166125e4565b815b9050806000036126365760405162461bcd60e51b815260206004820152601b60248201527f494e56414c49445f5a45524f5f4d41585f52454445454d41424c4500000000006044820152606401610d58565b60008185116126455784612647565b815b9050612655878460016136b3565b50600061266182611324565b905061266d8883613762565b845164ffffffffff161561273a578185602001516001600160d81b03166126949190614ec0565b6000036126b9576001600160a01b0388166000908152603e602052604081205561273a565b6126c2826138a0565b6001600160a01b0389166000908152603e60205260409020546126fe916001600160b81b031690600160281b90046001600160d81b03166150b9565b6001600160a01b0389166000908152603e6020526040902080546001600160d81b0392909216600160281b0264ffffffffff9092169190911790555b61276e6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001688836122c7565b866001600160a01b0316886001600160a01b03167f3f693fff038bb8a046aa76d9516190ac7444f7d69cf952c4cbdc086fdef2d6fc83856040516127bc929190918252602082015260400190565b60405180910390a35050505050505050565b6000816000036127f05760405162461bcd60e51b8152600401610d589061508c565b6000612806856127ff87611389565b60006136b3565b905060008184116128175783612819565b815b90508060000361283b5760405162461bcd60e51b8152600401610d589061508c565b6128458183614ec0565b6001600160a01b038088166000908152603d60205260409020919091556128b0907f0000000000000000000000000000000000000000000000000000000000000000167f00000000000000000000000000000000000000000000000000000000000000008784612b8c565b846001600160a01b0316866001600160a01b03167f9310ccfcb8de723f578a9e4282ea9f521f05ae40dc08f3068dfad528a65ee3c7836040516128f591815260200190565b60405180910390a395945050505050565b60006129128484611e71565b9050600019811461169f578181101561296d5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610d58565b61169f848484840361232a565b600061298584611389565b9050612993848260016136b3565b50826001600160a01b0316846001600160a01b031614612a9e5760006129b884611389565b90506129c6848260016136b3565b506001600160a01b0385166000908152603e602090815260409182902082518084019093525464ffffffffff8116808452600160281b9091046001600160d81b03169183019190915215612a9b57838303612a39576001600160a01b0386166000908152603e6020526040812055612a9b565b60208101516001600160d81b0316612a518585614ec0565b1015612a9b57612a618484614ec0565b6001600160a01b0387166000908152603e60205260409020805464ffffffffff166001600160b81b0392909216600160281b029190911790555b50505b61169f848484613909565b6000612ab482611389565b905080600003612b065760405162461bcd60e51b815260206004820152601b60248201527f494e56414c49445f42414c414e43455f4f4e5f434f4f4c444f574e00000000006044820152606401610d58565b60408051808201825264ffffffffff42811682526001600160d81b0380851660208085019182526001600160a01b0388166000818152603e9092529086902094519151909216600160281b0292169190911790915590517f8a05f911d8ab7fc50fec37ef4ba7f9bfcb1a3c191c81dcd824ad0946c4e20d659061214c9084815260200190565b6040516001600160a01b038085166024830152831660448201526064810182905261169f9085906323b872dd60e01b906084016122f3565b6001600160a01b038216612c0e5760405162461bcd60e51b8152602060048201526011602482015270494e56414c49445f44454c45474154454560781b6044820152606401610d58565b6000612c1982612cc5565b925050506000612c2885611389565b90506000612c368684612d04565b6001600160a01b03878116600090815260208690526040902080546001600160a01b0319169188169190911790559050612c7281868487613ab8565b846001600160a01b0316866001600160a01b03167fe8d51c8e11bd570db1734c8ec775785330e77007feed45c43b608ef33ff914bd86604051612cb59190615102565b60405180910390a3505050505050565b6000808080846001811115612cdc57612cdc615053565b03612cf157506006915060079050603f612cfd565b50604091506041905060425b9193909250565b6001600160a01b03808316600090815260208390526040812054909116806110c25783915050610f54565b605154600160d81b900460ff1615612d7c5760405162461bcd60e51b815260206004820152601060248201526f534c415348494e475f4f4e474f494e4760801b6044820152606401610d58565b80600003612d9c5760405162461bcd60e51b8152600401610d589061508c565b6000612da783611389565b90506000612dbf843084612dba60025490565b613cbc565b90508015612e42576001600160a01b0384166000908152603d6020526040902054612deb908290614f44565b6001600160a01b0385166000818152603d60209081526040918290209390935580519182529181018390527f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a76910160405180910390a15b6000612e4d846113a4565b9050612e846001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016873087612b8c565b612e8e8582613d7d565b846001600160a01b0316866001600160a01b03167f6c86f3fd5118b3aa8bb4f389a617046de0a3d3d477de1a1673d227f802f616dc8684604051612cb5929190918252602082015260400190565b6127108110612f2d5760405162461bcd60e51b815260206004820152601b60248201527f494e56414c49445f534c415348494e475f50455243454e5441474500000000006044820152606401610d58565b60508190556040518181527fb79c2d6c7f5c95eec9dc05affc0ed002620a4ec6d72b7b0744cc8638168c600a906020015b60405180910390a150565b604f8190556040518181527fbbf67247b5c97564e30ffc0a355e71c006836de7b9149e09e3d5d6054cb0335590602001612f5e565b600080805b83518110156130a4576000603c6000868481518110612fc457612fc4614f90565b602090810291909101810151516001600160a01b031682528101919091526040016000908120600181015481548851929450613032926001600160801b0380831692600160801b900416908a908890811061302157613021614f90565b602002602001015160400151613e48565b905061308386848151811061304957613049614f90565b602002602001015160200151828460020160008b6001600160a01b03166001600160a01b0316815260200190815260200160002054613f53565b61308d9085614f44565b93505050808061309c90614fc8565b915050612fa3565b509392505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03161461314f5760405162461bcd60e51b815260206004820181905260248201527f5245574152445f544f4b454e5f49535f4e4f545f5354414b45445f544f4b454e6044820152606401610d58565b60006131658561315e87611389565b60016136b3565b905060008184116131765783613178565b815b90508015611a605761318b8630836127ce565b50611a60308683612d2f565b60408051600380825260808201909252600091816020015b60408051808201909152600080825260208201528152602001906001900390816131af579050509050604051806040016040528060008152602001876001600160a01b03168152508160008151811061320a5761320a614f90565b6020026020010181905250604051806040016040528060018152602001866001600160a01b03168152508160018151811061324757613247614f90565b6020026020010181905250604051806040016040528060028152602001856001600160a01b03168152508160028151811061328457613284614f90565b602002602001018190525061329881613f7f565b6132a183612edc565b6132aa82612f69565b611478670de0b6b3a7640000612222565b60005b8151811015611074576000603c60008484815181106132df576132df614f90565b6020026020010151604001516001600160a01b03166001600160a01b03168152602001908152602001600020905061335283838151811061332257613322614f90565b6020026020010151604001518285858151811061334157613341614f90565b60200260200101516020015161415b565b5082828151811061336557613365614f90565b60209081029190910101515181546fffffffffffffffffffffffffffffffff19166001600160801b0390911617815582518390839081106133a8576133a8614f90565b6020026020010151604001516001600160a01b03167f87fa03892a0556cb6b8f97e6d533a150d4d55fcbf275fff5fa003fa636bcc7fa8484815181106133f0576133f0614f90565b602090810291909101810151516040516001600160801b0390911681520160405180910390a2508061342181614fc8565b9150506132be565b60515460009061344990605290600160e01b900463ffffffff1684614213565b670de0b6b3a764000061345e87878787614320565b6134689190614f57565b611a609190614f6e565b60006001600160d81b038211156134db5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663136206269747360c81b6064820152608401610d58565b5090565b600064ffffffffff8211156134db5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526530206269747360d01b6064820152608401610d58565b806001600160d81b03166000036135935760405162461bcd60e51b81526020600482015260126024820152715a45524f5f45584348414e47455f5241544560701b6044820152606401610d58565b605180546001600160d81b0319166001600160d81b0383169081179091556040519081527fa9c433f9734baa3cf48b209454bb0ace054e191f677ba50e74b696c0d35ef26290602001612f5e565b6000613636826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166143fa9092919063ffffffff16565b80519091501561106457808060200190518101906136549190614fa6565b6110645760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610d58565b6000806136c5853086612dba60025490565b6001600160a01b0386166000908152603d6020526040812054919250906136ed908390614f44565b90508115611a60578315613717576001600160a01b0386166000908152603d602052604090208190555b604080516001600160a01b0388168152602081018490527f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a76910160405180910390a195945050505050565b6001600160a01b0382166137c25760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610d58565b6137ce82600083614409565b6001600160a01b038216600090815260208190526040902054818110156138425760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610d58565b6001600160a01b0383166000818152602081815260408083208686039055600280548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b60006001600160b81b038211156134db5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663834206269747360c81b6064820152608401610d58565b6001600160a01b03831661396d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610d58565b6001600160a01b0382166139cf5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610d58565b6139da838383614409565b6001600160a01b03831660009081526020819052604090205481811015613a525760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610d58565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a361169f565b826001600160a01b0316846001600160a01b0316031561169f57600080613ade83612cc5565b5090925090506001600160a01b03861615613bcf576001600160a01b0386166000908152602082905260408120548015613b5e576001600160a01b038816600090815260208590526040812090613b36600184614ec0565b8152602081019190915260400160002054600160801b90046001600160801b03169150613b6a565b613b6788611389565b91505b613b8084848a85613b7b8b82614ec0565b614588565b6001600160a01b0388167fa0a19463ee116110c9b282012d9b65cc5522dc38a9520340cbaf3142e550127f613bb58885614ec0565b87604051613bc4929190615110565b60405180910390a250505b6001600160a01b03851615611478576001600160a01b0385166000908152602082905260408120548015613c49576001600160a01b038716600090815260208590526040812090613c21600184614ec0565b8152602081019190915260400160002054600160801b90046001600160801b03169150613c55565b613c5287611389565b91505b613c6684848985613b7b8b82614f44565b6001600160a01b0387167fa0a19463ee116110c9b282012d9b65cc5522dc38a9520340cbaf3142e550127f613c9b8885614f44565b87604051613caa929190615110565b60405180910390a25050505050505050565b6001600160a01b038084166000908152603c602090815260408083209388168352600284019091528120549091908280613cf788858861415b565b9050808314613d71578615613d1457613d11878285613f53565b91505b6001600160a01b03808a1660008181526002870160205260409081902084905551918a16917fbb123b5c06d5408bbea3c4fef481578175cfb432e3b482c6186f02ed9086585b90613d689085815260200190565b60405180910390a35b50979650505050505050565b6001600160a01b038216613dd35760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610d58565b613ddf60008383614409565b8060026000828254613df19190614f44565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6000831580613e55575081155b80613e68575042836001600160801b0316145b80613e9c57507f0000000000000000000000000000000000000000000000000000000000000000836001600160801b031610155b15613ea8575083611381565b60007f00000000000000000000000000000000000000000000000000000000000000004211613ed75742613ef9565b7f00000000000000000000000000000000000000000000000000000000000000005b90506000613f106001600160801b03861683614ec0565b90508684613f206012600a615208565b613f2a848a614f57565b613f349190614f57565b613f3e9190614f6e565b613f489190614f44565b979650505050505050565b6000613f616012600a615208565b613f6b8385614ec0565b613f759086614f57565b6110bf9190614f6e565b60005b81518110156110745760006001600160a01b031660456000848481518110613fac57613fac614f90565b602090810291909101810151518252810191909152604001600020546001600160a01b031614801561400e575060006001600160a01b0316828281518110613ff657613ff6614f90565b6020026020010151602001516001600160a01b031614155b61405a5760405162461bcd60e51b815260206004820152601b60248201527f41444d494e5f43414e4e4f545f42455f494e495449414c495a454400000000006044820152606401610d58565b81818151811061406c5761406c614f90565b6020026020010151602001516045600084848151811061408e5761408e614f90565b602002602001015160000151815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055508181815181106140de576140de614f90565b6020026020010151602001516001600160a01b03167f83a9ddad961dcb7c6894c9585a16ff7792c2ec8281256a3cc7303ae830152dcf83838151811061412657614126614f90565b60200260200101516000015160405161414191815260200190565b60405180910390a28061415381614fc8565b915050613f82565b6001820154825460009190600160801b90046001600160801b031642819003614186575090506110c2565b84546000906141a19084906001600160801b03168488613e48565b90508281146141f057600186018190556040518181526001600160a01b038816907f5777ca300dfe5bead41006fbce4389794dbc0ed8d6cccebfaf94630aa04184bc9060200160405180910390a25b85546001600160801b03428116600160801b029116178655925050509392505050565b600019820160009081526020849052604081205464ffffffffff16821061425e57506000198201600090815260208490526040902054600160281b90046001600160d81b03166110c2565b600060001984015b818111156142f75760028282030481036000818152602088815260409182902082518084019093525464ffffffffff8116808452600160281b9091046001600160d81b0316918301919091528690036142d157602001516001600160d81b031693506110c292505050565b805164ffffffffff168611156142e9578193506142f0565b6001820392505b5050614266565b5060009081526020949094525050604090912054600160281b90046001600160d81b0316919050565b6000438211156143695760405162461bcd60e51b815260206004820152601460248201527324a72b20a624a22fa12627a1a5afa72aa6a122a960611b6044820152606401610d58565b6001600160a01b0383166000908152602085905260408120549081900361439b5761439384611389565b915050611381565b6001600160a01b0384166000908152602087815260408083208380529091529020546001600160801b03168310156143d7576000915050611381565b6001600160a01b0384166000908152602087905260409020611acf90828561469e565b60606110bf84846000856147aa565b6053546001600160a01b031680156144e057806001600160a01b0316635b9c4cf1858561443588611389565b61443e88611389565b6040516001600160e01b031960e087901b1681526001600160a01b039485166004820152939092166024840152604483015260648201526084810185905260a401600060405180830381600087803b15801561449957600080fd5b505af19250505080156144aa575060015b6144e0573d8080156144d8576040519150601f19603f3d011682016040523d82523d6000602084013e6144dd565b606091505b50505b6001600160a01b038085166000908152603f6020526040808220548684168352912054908216911681614511578591505b6001600160a01b0381166145225750835b61452f8282866000613ab8565b6001600160a01b03808716600090815260426020526040808220548884168352912054908216911681614560578791505b6001600160a01b0381166145715750855b61457e8282886001613ab8565b5050505050505050565b6001600160a01b038316600090815260208581526040808320549188905290912043919081158015906145ea57506001600160801b0383168160006145ce600186614ec0565b81526020810191909152604001600020546001600160801b0316145b1561462e57838160006145fe600186614ec0565b8152602081019190915260400160002080546001600160801b03928316600160801b02921691909117905561457e565b6040805180820182526001600160801b038086168252868116602080840191825260008781529086905293909320915192518116600160801b02921691909117905561467b826001614f44565b6001600160a01b0387166000908152602089905260409020555050505050505050565b60001982016000908152602084905260408120546001600160801b031682106146eb57506000198201600090815260208490526040902054600160801b90046001600160801b03166110c2565b600060001984015b81811115614781576002828203048103600081815260208881526040918290208251808401909352546001600160801b03808216808552600160801b909204169183019190915286900361475957602001516001600160801b031693506110c292505050565b80516001600160801b03168611156147735781935061477a565b6001820392505b50506146f3565b5060009081526020949094525050604090912054600160801b90046001600160801b0316919050565b60608247101561480b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610d58565b600080866001600160a01b031685876040516148279190615214565b60006040518083038185875af1925050503d8060008114614864576040519150601f19603f3d011682016040523d82523d6000602084013e614869565b606091505b5091509150613f4887838387606083156148e45782516000036148dd576001600160a01b0385163b6148dd5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610d58565b5081611381565b61138183838151156148f95781518083602001fd5b8060405162461bcd60e51b8152600401610d5891906149a4565b6001600160a01b038116811461113057600080fd5b6000806040838503121561493b57600080fd5b823561494681614913565b946020939093013593505050565b60005b8381101561496f578181015183820152602001614957565b50506000910152565b60008151808452614990816020860160208601614954565b601f01601f19169290920160200192915050565b6020815260006110c26020830184614978565b6000602082840312156149c957600080fd5b81356110c281614913565b6000602082840312156149e657600080fd5b5035919050565b600080600060608486031215614a0257600080fd5b8335614a0d81614913565b92506020840135614a1d81614913565b929592945050506040919091013590565b60008060408385031215614a4157600080fd5b8235614a4c81614913565b91506020830135614a5c81614913565b809150509250929050565b803560028110614a7657600080fd5b919050565b60008060408385031215614a8e57600080fd5b8235614a9981614913565b9150614aa760208401614a67565b90509250929050565b803560ff81168114614a7657600080fd5b60008060008060008060c08789031215614ada57600080fd5b8635614ae581614913565b95506020870135945060408701359350614b0160608801614ab0565b92506080870135915060a087013590509295509295509295565b600060208284031215614b2d57600080fd5b813563ffffffff811681146110c257600080fd5b60008060008060808587031215614b5757600080fd5b8435614b6281614913565b93506020850135614b7281614913565b93969395505050506040820135916060013590565b600080600080600060a08688031215614b9f57600080fd5b8535614baa81614913565b94506020860135614bba81614913565b93506040860135614bca81614913565b94979396509394606081013594506080013592915050565b60008060408385031215614bf557600080fd5b823591506020830135614a5c81614913565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff81118282101715614c4057614c40614c07565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715614c6f57614c6f614c07565b604052919050565b60006020808385031215614c8a57600080fd5b823567ffffffffffffffff80821115614ca257600080fd5b818501915085601f830112614cb657600080fd5b813581811115614cc857614cc8614c07565b614cd6848260051b01614c46565b81815284810192506060918202840185019188831115614cf557600080fd5b938501935b82851015613d715780858a031215614d125760008081fd5b614d1a614c1d565b85356001600160801b0381168114614d325760008081fd5b81528587013587820152604080870135614d4b81614913565b9082015284529384019392850192614cfa565b600080600060608486031215614d7357600080fd5b8335614d7e81614913565b925060208401359150614d9360408501614a67565b90509250925092565b600080600080600080600060e0888a031215614db757600080fd5b8735614dc281614913565b96506020880135614dd281614913565b95506040880135945060608801359350614dee60808901614ab0565b925060a0880135915060c0880135905092959891949750929550565b600080600060608486031215614e1f57600080fd5b8335614e2a81614913565b95602085013595506040909401359392505050565b600080600080600080600060e0888a031215614e5a57600080fd5b8735614e6581614913565b9650614dd260208901614a67565b60208082526019908201527f43414c4c45525f4e4f545f534c415348494e475f41444d494e00000000000000604082015260600190565b634e487b7160e01b600052601160045260246000fd5b81810381811115610f5457610f54614eaa565b600181811c90821680614ee757607f821691505b602082108103614f0757634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526017908201527f43414c4c45525f4e4f545f434c41494d5f48454c504552000000000000000000604082015260600190565b80820180821115610f5457610f54614eaa565b8082028115828204841417610f5457610f54614eaa565b600082614f8b57634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b600060208284031215614fb857600080fd5b815180151581146110c257600080fd5b600060018201614fda57614fda614eaa565b5060010190565b61190160f01b81526002810192909252602282015260420190565b602080825260119082015270494e56414c49445f5349474e415455524560781b604082015260600190565b60208082526012908201527124a72b20a624a22fa2ac2824a920aa24a7a760711b604082015260600190565b634e487b7160e01b600052602160045260246000fd5b600063ffffffff80831681810361508257615082614eaa565b6001019392505050565b6020808252601390820152721253959053125117d6915493d7d05353d55395606a1b604082015260600190565b6001600160d81b038281168282160390808211156150d9576150d9614eaa565b5092915050565b600281106150fe57634e487b7160e01b600052602160045260246000fd5b9052565b60208101610f5482846150e0565b828152604081016110c260208301846150e0565b600181815b8085111561515f57816000190482111561514557615145614eaa565b8085161561515257918102915b93841c9390800290615129565b509250929050565b60008261517657506001610f54565b8161518357506000610f54565b816001811461519957600281146151a3576151bf565b6001915050610f54565b60ff8411156151b4576151b4614eaa565b50506001821b610f54565b5060208310610133831016604e8410600b84101617156151e2575081810a610f54565b6151ec8383615124565b806000190482111561520057615200614eaa565b029392505050565b60006110c28383615167565b60008251615226818460208701614954565b919091019291505056fea2646970667358221220eca7538023765a4de548dace73c5919366f9605051f5141240ca82e0c4ea703c64736f6c634300081100330000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae90000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000000000000000000000000000000000000002a30000000000000000000000000025f2226b597e8f9514b3f68f00f494cf4f286491000000000000000000000000ee56e2b3d491590b5b31738cc34d5232f378a8d500000000000000000000000000000000000000000000000000000000bc180c38

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106104965760003560e01c80638c9a281d11610262578063aff05aa911610151578063dbc0ed8a116100ce578063eab5231811610092578063eab5231814610c65578063f036bc6814610c78578063f11b818814610c8c578063f34d96da14610cee578063f713d8a814610cf6578063fde9eb6914610d0957600080fd5b8063dbc0ed8a14610c1f578063dc937e1c14610c27578063dd62ed3e14610c3a578063dde43cba14610c4d578063e6aa216c14610c5457600080fd5b8063c2ffbb9111610115578063c2ffbb9114610bac578063c3863ada14610bbf578063c3cda52014610bd2578063cbcbb50714610be5578063d505accf14610c0c57600080fd5b8063aff05aa914610b4b578063b2a5dbfa14610b53578063b2f4201d14610b66578063b9844d8d14610b79578063c18f539a14610b9957600080fd5b80639a99b4f0116101df578063a9059cbb116101a3578063a9059cbb14610ae3578063aa9fbe0214610af6578063aaf5eb6814610b1d578063ab406fe614610b25578063adc9772e14610b3857600080fd5b80639a99b4f014610a8f5780639c9b515414610aa25780639e3ffce014610ab5578063a457c2d714610abd578063a6b63eb814610ad057600080fd5b8063946776cd11610226578063946776cd14610a13578063955e18af14610a3a57806395d89b4114610a4d578063981b24d014610a5557806399248ea714610a6857600080fd5b80638c9a281d146109325780638dbefee21461093a5780638e9b2ca41461094d5780638ef98e0e1461095c578063919cd40f146109ec57600080fd5b806345755dd6116103895780636f50458d1161030657806374011f56116102ca57806374011f56146108a457806378160376146108b7578063787a08a6146108d75780637b5b1157146108df5780637bb73c97146108f25780637e90d7ef1461091257600080fd5b80636f50458d1461085857806370a082311461086b578063727a5d571461087e57806372b49d631461082957806373d6a8891461089157600080fd5b80635b3cc0cf1161034d5780635b3cc0cf146107925780635c19a95c146107f157806360ba192b14610804578063616e0bf9146108295780636198e1351461083157600080fd5b806345755dd6146107095780634575e69b1461071c5780634998fffd146107455780634cdad5061461075857806358146d171461076b57600080fd5b806323b872dd116104175780633373ee4c116103db5780633373ee4c14610661578063359c4a961461069f5780633644e515146106c657806339509351146106cf57806341cbf54a146106e257600080fd5b806323b872dd146105d8578063250201db146105eb57806330adf81f146105fe578063312f6b8314610625578063313ce5671461064c57600080fd5b8063112d037c1161045e578063112d037c14610582578063174ed5421461059757806318160ddd146105aa5780631e9a6950146105b257806320fb80b5146105c557600080fd5b806302fb4d851461049b57806306fdde03146104c1578063091030c3146104d6578063095ea7b314610534578063111fd88b14610557575b600080fd5b6104ae6104a9366004614928565b610d1c565b6040519081526020015b60405180910390f35b6104c9610f5a565b6040516104b891906149a4565b61050f6104e43660046149b7565b603e6020526000908152604090205464ffffffffff811690600160281b90046001600160d81b031682565b6040805164ffffffffff90931683526001600160d81b039091166020830152016104b8565b610547610542366004614928565b610fec565b60405190151581526020016104b8565b61056a6105653660046149d4565b611004565b6040516001600160a01b0390911681526020016104b8565b6105956105903660046149ed565b61101f565b005b60535461056a906001600160a01b031681565b6002546104ae565b6105956105c0366004614928565b611069565b6104ae6105d33660046149ed565b611078565b6105476105e63660046149ed565b6110c9565b6105956105f93660046149b7565b6110ed565b6104ae7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b61056a7f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae981565b60125b60405160ff90911681526020016104b8565b6104ae61066f366004614a2e565b6001600160a01b038082166000908152603c60209081526040808320938616835260029093019052205492915050565b6104ae7f000000000000000000000000000000000000000000000000000000000002a30081565b6104ae60435481565b6105476106dd366004614928565b611133565b6104ae7f9a9a49b990ba9bb39f8048c490a40ab25c18f55d208d5fbcf958261a9b48716d81565b6105956107173660046149d4565b611155565b61056a61072a3660046149d4565b6000908152604660205260409020546001600160a01b031690565b6105956107533660046149b7565b6112ba565b6104ae6107663660046149d4565b611324565b61077a670de0b6b3a764000081565b6040516001600160d81b0390911681526020016104b8565b6107d16107a0366004614928565b60066020908152600092835260408084209091529082529020546001600160801b0380821691600160801b90041682565b604080516001600160801b039384168152929091166020830152016104b8565b6105956107ff3660046149b7565b61134f565b605154600160e01b900463ffffffff1660405163ffffffff90911681526020016104b8565b604f546104ae565b6104ae7f0000000000000000000000000000000000000000000000000de0b6b3a764000081565b61056a610866366004614a7b565b611367565b6104ae6108793660046149b7565b611389565b6104ae61088c3660046149d4565b6113a4565b61059561089f366004614ac1565b6113c7565b6105956108b23660046149d4565b611480565b6104c9604051806040016040528060018152602001603160f81b81525081565b6105956114c3565b6105956108ed3660046149d4565b6114ce565b6104ae6109003660046149b7565b60076020526000908152604090205481565b6104ae6109203660046149b7565b603d6020526000908152604090205481565b6104ae600081565b6104ae6109483660046149b7565b611541565b6104ae670de0b6b3a764000081565b6109c161096a366004614b1b565b60408051808201909152600080825260208201525063ffffffff1660009081526052602090815260409182902082518084019093525464ffffffffff81168352600160281b90046001600160d81b03169082015290565b60408051825164ffffffffff1681526020928301516001600160d81b031692810192909252016104b8565b6104ae7f000000000000000000000000000000000000000000000000000000012080ca6381565b61056a7f00000000000000000000000025f2226b597e8f9514b3f68f00f494cf4f28649181565b6104ae610a48366004614928565b61161c565b6104c9611629565b6104ae610a633660046149d4565b611638565b61056a7f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae981565b610595610a9d366004614928565b611643565b610595610ab0366004614b41565b61164e565b6104ae600181565b610547610acb366004614928565b6116a5565b610595610ade366004614b87565b611720565b610547610af1366004614928565b611838565b6104ae7f10d8d059343739efce7dad10d09f0806da52b252b3e6a7951920d2d6ec4102e581565b61064f601281565b610595610b33366004614be2565b611846565b610595610b46366004614928565b611909565b610595611914565b610595610b61366004614c77565b611986565b6104ae610b74366004614a7b565b611a41565b6104ae610b873660046149b7565b60446020526000908152604090205481565b6104ae610ba73660046149ed565b611a69565b6104ae610bba366004614d5e565b611ab0565b60085461056a906001600160a01b031681565b610595610be0366004614ac1565b611ad9565b61056a7f000000000000000000000000ee56e2b3d491590b5b31738cc34d5232f378a8d581565b610595610c1a366004614d9c565b611c9e565b6104ae600281565b610595610c35366004614a7b565b611e66565b6104ae610c48366004614a2e565b611e71565b60056104ae565b6051546001600160d81b031661077a565b610595610c73366004614e0a565b611e9c565b60515461054790600160d81b900460ff1681565b610cc8610c9a3660046149b7565b603c60205260009081526040902080546001909101546001600160801b0380831692600160801b9004169083565b604080516001600160801b039485168152939092166020840152908201526060016104b8565b6050546104ae565b610595610d04366004614e3f565b611eb3565b610595610d173660046149d4565b612087565b6000610d286000611004565b6001600160a01b0316336001600160a01b031614610d615760405162461bcd60e51b8152600401610d5890614e73565b60405180910390fd5b605154600160d81b900460ff1615610dbb5760405162461bcd60e51b815260206004820152601d60248201527f50524556494f55535f534c415348494e475f4e4f545f534554544c45440000006044820152606401610d58565b60008211610df95760405162461bcd60e51b815260206004820152600b60248201526a16915493d7d05353d5539560aa1b6044820152606401610d58565b6000610e0460025490565b90506000610e1182611324565b90506000610e2a6050548361215890919063ffffffff16565b905080851115610e38578094505b7f0000000000000000000000000000000000000000000000000de0b6b3a7640000610e638684614ec0565b1015610ea85760405162461bcd60e51b815260206004820152601460248201527352454d41494e494e475f4c545f4d494e494d554d60601b6044820152606401610d58565b6051805460ff60d81b1916600160d81b179055610ed6610ed1610ecb8785614ec0565b856121e4565b612222565b610f0a6001600160a01b037f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae91687876122c7565b856001600160a01b03167f4ed05e9673c26d2ed44f7ef6a7f2942df0ee3b5e1e17db4b99f9dcd261a339cd86604051610f4591815260200190565b60405180910390a28493505050505b92915050565b606060038054610f6990614ed3565b80601f0160208091040260200160405190810160405280929190818152602001828054610f9590614ed3565b8015610fe25780601f10610fb757610100808354040283529160200191610fe2565b820191906000526020600020905b815481529060010190602001808311610fc557829003601f168201915b5050505050905090565b600033610ffa81858561232a565b5060019392505050565b6000908152604560205260409020546001600160a01b031690565b6110296002611004565b6001600160a01b0316336001600160a01b0316146110595760405162461bcd60e51b8152600401610d5890614f0d565b61106483838361244e565b505050565b61107433838361244e565b5050565b60006110846002611004565b6001600160a01b0316336001600160a01b0316146110b45760405162461bcd60e51b8152600401610d5890614f0d565b6110bf8484846127ce565b90505b9392505050565b6000336110d7858285612906565b6110e285858561297a565b506001949350505050565b6110f76002611004565b6001600160a01b0316336001600160a01b0316146111275760405162461bcd60e51b8152600401610d5890614f0d565b61113081612aa9565b50565b600033610ffa8185856111468383611e71565b6111509190614f44565b61232a565b7f0000000000000000000000000000000000000000000000000de0b6b3a76400008110156111b95760405162461bcd60e51b8152602060048201526011602482015270414d4f554e545f4c545f4d494e494d554d60781b6044820152606401610d58565b60006111c460025490565b90507f0000000000000000000000000000000000000000000000000de0b6b3a764000081101561122a5760405162461bcd60e51b81526020600482015260116024820152705348415245535f4c545f4d494e494d554d60781b6044820152606401610d58565b600061123582611324565b905061124d610ed16112478584614f44565b846121e4565b6112826001600160a01b037f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae916333086612b8c565b6040518381527f278e51d3323fbf18b9fb8df3f8b97e31b145bc1146c52e764cf4aa1bfc4ba17d9060200160405180910390a1505050565b73ee56e2b3d491590b5b31738cc34d5232f378a8d533146112da57600080fd5b605380546001600160a01b0319166001600160a01b0383169081179091556040517f62bbced765bccc9ed93d0bae1b2a8c86e13b4663f8bf27d5936d9d619194c8a990600090a250565b6051546000906001600160d81b031661134583670de0b6b3a7640000614f57565b610f549190614f6e565b61135b33826000612bc4565b61113033826001612bc4565b60008061137383612cc5565b925050506113818482612d04565b949350505050565b6001600160a01b031660009081526020819052604090205490565b605154600090670de0b6b3a764000090611345906001600160d81b031684614f57565b60405163d505accf60e01b81526001600160a01b038781166004830152306024830152604482018790526064820186905260ff8516608483015260a4820184905260c482018390527f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9169063d505accf9060e401600060405180830381600087803b15801561145557600080fd5b505af1158015611469573d6000803e3d6000fd5b50505050611478868787612d2f565b505050505050565b61148a6000611004565b6001600160a01b0316336001600160a01b0316146114ba5760405162461bcd60e51b8152600401610d5890614e73565b61113081612edc565b6114cc33612aa9565b565b6114d86001611004565b6001600160a01b0316336001600160a01b0316146115385760405162461bcd60e51b815260206004820152601960248201527f43414c4c45525f4e4f545f434f4f4c444f574e5f41444d494e000000000000006044820152606401610d58565b61113081612f69565b604080516001808252818301909252600091829190816020015b611588604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b81526020019060019003908161155b5790505090506040518060600160405280306001600160a01b031681526020016115c085611389565b81526020016115ce60025490565b815250816000815181106115e4576115e4614f90565b60200260200101819052506115f98382612f9e565b6001600160a01b0384166000908152603d60205260409020546110c29190614f44565b60006110c23384846130ac565b606060048054610f6990614ed3565b6000610f5460025490565b6110643383836127ce565b6116586002611004565b6001600160a01b0316336001600160a01b0316146116885760405162461bcd60e51b8152600401610d5890614f0d565b6116938484846127ce565b5061169f84848361244e565b50505050565b600033816116b38286611e71565b9050838110156117135760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610d58565b6110e2828686840361232a565b600954600590811161178b5760405162461bcd60e51b815260206004820152602e60248201527f436f6e747261637420696e7374616e63652068617320616c726561647920626560448201526d195b881a5b9a5d1a585b1a5e995960921b6064820152608401610d58565b600981905561179d8686868686613197565b60405163095ea7b360e01b815230600482015260001960248201527f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae96001600160a01b03169063095ea7b3906044016020604051808303816000875af115801561180b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182f9190614fa6565b50505050505050565b600033610ffa81858561297a565b60008281526045602052604090205482906001600160a01b031633146118a65760405162461bcd60e51b815260206004820152601560248201527421a0a62622a92fa727aa2fa927a622afa0a226a4a760591b6044820152606401610d58565b60008381526046602090815260409182902080546001600160a01b0319166001600160a01b03861690811790915591518581527fc3d1bf52795a20771ee6de3e59948fd83e10db956122d4709a3b86c512963855910160405180910390a2505050565b611074338383612d2f565b61191e6000611004565b6001600160a01b0316336001600160a01b03161461194e5760405162461bcd60e51b8152600401610d5890614e73565b6051805460ff60d81b191690556040517fcdee157e87ba915be681d4fa3f3d511afe7348eca06448a3accd6ac227fa40af90600090a1565b336001600160a01b037f000000000000000000000000ee56e2b3d491590b5b31738cc34d5232f378a8d516146119f65760405162461bcd60e51b815260206004820152601560248201527427a7262cafa2a6a4a9a9a4a7a72fa6a0a720a3a2a960591b6044820152606401610d58565b60005b8151811015611a3757600254828281518110611a1757611a17614f90565b602090810291909101810151015280611a2f81614fc8565b9150506119f9565b50611130816132bb565b6000806000611a4f84612cc5565b5091509150611a6082828743613429565b95945050505050565b6000611a756002611004565b6001600160a01b0316336001600160a01b031614611aa55760405162461bcd60e51b8152600401610d5890614f0d565b6110bf8484846130ac565b6000806000611abe84612cc5565b5091509150611acf82828888613429565b9695505050505050565b604080517f9a9a49b990ba9bb39f8048c490a40ab25c18f55d208d5fbcf958261a9b48716d60208201526001600160a01b03881691810191909152606081018690526080810185905260009060a001604051602081830303815290604052805190602001209050600060435482604051602001611b57929190614fe1565b60408051601f198184030181528282528051602091820120600080855291840180845281905260ff89169284019290925260608301879052608083018690529092509060019060a0016020604051602081039080840390855afa158015611bc2573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611bf55760405162461bcd60e51b8152600401610d5890614ffc565b6001600160a01b0381166000908152604460205260408120805491611c1983614fc8565b919050558814611c5b5760405162461bcd60e51b815260206004820152600d60248201526c494e56414c49445f4e4f4e434560981b6044820152606401610d58565b86421115611c7b5760405162461bcd60e51b8152600401610d5890615027565b611c87818a6000612bc4565b611c93818a6001612bc4565b505050505050505050565b6001600160a01b038716611ce45760405162461bcd60e51b815260206004820152600d60248201526c24a72b20a624a22fa7aba722a960991b6044820152606401610d58565b83421115611d045760405162461bcd60e51b8152600401610d5890615027565b6001600160a01b0387811660008181526044602090815260408083205460435482517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958c166060860152608085018b905260a0850181905260c08086018b90528251808703909101815260e086019092528151919092012090939192611d9b92919061010001614fe1565b60408051601f1981840301815282825280516020918201206000845290830180835281905260ff8816918301919091526060820186905260808201859052915060019060a0016020604051602081039080840390855afa158015611e03573d6000803e3d6000fd5b505050602060405103516001600160a01b0316896001600160a01b031614611e3d5760405162461bcd60e51b8152600401610d5890614ffc565b6001600160a01b0389166000908152604460205260409020600183019055611c9389898961232a565b611074338383612bc4565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b611ea73384846127ce565b5061106433848361244e565b60007f10d8d059343739efce7dad10d09f0806da52b252b3e6a7951920d2d6ec4102e588886001811115611ee957611ee9615053565b6040805160208101949094526001600160a01b039092169183019190915260608201526080810187905260a0810186905260c001604051602081830303815290604052805190602001209050600060435482604051602001611f4c929190614fe1565b60408051601f198184030181528282528051602091820120600080855291840180845281905260ff89169284019290925260608301879052608083018690529092509060019060a0016020604051602081039080840390855afa158015611fb7573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611fea5760405162461bcd60e51b8152600401610d5890614ffc565b6001600160a01b038116600090815260446020526040812080549161200e83614fc8565b9190505588146120505760405162461bcd60e51b815260206004820152600d60248201526c494e56414c49445f4e4f4e434560981b6044820152606401610d58565b864211156120705760405162461bcd60e51b8152600401610d5890615027565b61207b818b8b612bc4565b50505050505050505050565b60008181526046602052604090205481906001600160a01b031633146120ef5760405162461bcd60e51b815260206004820152601d60248201527f43414c4c45525f4e4f545f50454e44494e475f524f4c455f41444d494e0000006044820152606401610d58565b60008281526045602090815260408083208054336001600160a01b0319918216811790925560468452938290208054909416909355518481527f83a9ddad961dcb7c6894c9585a16ff7792c2ec8281256a3cc7303ae830152dcf91015b60405180910390a25050565b6000821580612165575081155b1561217257506000610f54565b61217e82600019614f6e565b8311156121cd5760405162461bcd60e51b815260206004820152601c60248201527f4d4154485f4d554c5449504c49434154494f4e5f4f564552464c4f57000000006044820152606401610d58565b6127106121da8385614f57565b6110c29190614f6e565b60006110c2836001816121ff670de0b6b3a764000087614f57565b6122099190614f44565b6122139190614ec0565b61221d9190614f6e565b613472565b6040518060400160405280612236436134df565b64ffffffffff90811682526001600160d81b038085166020938401526051805463ffffffff600160e01b9182900481166000908152605287526040902087519790960151909316600160281b0295909316949094179092558254601c926122a09290910416615069565b91906101000a81548163ffffffff021916908363ffffffff16021790555061113081613545565b6040516001600160a01b03831660248201526044810182905261106490849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526135e1565b6001600160a01b03831661238c5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610d58565b6001600160a01b0382166123ed5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610d58565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b8060000361246e5760405162461bcd60e51b8152600401610d589061508c565b6001600160a01b0383166000908152603e602090815260409182902082518084019093525464ffffffffff81168352600160281b90046001600160d81b031690820152605154600160d81b900460ff166125ad57604f5481516124d8919064ffffffffff16614f44565b421161251e5760405162461bcd60e51b815260206004820152601560248201527424a729aaa32324a1a4a2a72a2fa1a7a7a62227aba760591b6044820152606401610d58565b604f5481517f000000000000000000000000000000000000000000000000000000000002a300916125559164ffffffffff16614f44565b61255f9042614ec0565b11156125ad5760405162461bcd60e51b815260206004820152601760248201527f554e5354414b455f57494e444f575f46494e49534845440000000000000000006044820152606401610d58565b60006125b885611389565b605154909150600090600160d81b900460ff166125e25782602001516001600160d81b03166125e4565b815b9050806000036126365760405162461bcd60e51b815260206004820152601b60248201527f494e56414c49445f5a45524f5f4d41585f52454445454d41424c4500000000006044820152606401610d58565b60008185116126455784612647565b815b9050612655878460016136b3565b50600061266182611324565b905061266d8883613762565b845164ffffffffff161561273a578185602001516001600160d81b03166126949190614ec0565b6000036126b9576001600160a01b0388166000908152603e602052604081205561273a565b6126c2826138a0565b6001600160a01b0389166000908152603e60205260409020546126fe916001600160b81b031690600160281b90046001600160d81b03166150b9565b6001600160a01b0389166000908152603e6020526040902080546001600160d81b0392909216600160281b0264ffffffffff9092169190911790555b61276e6001600160a01b037f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae91688836122c7565b866001600160a01b0316886001600160a01b03167f3f693fff038bb8a046aa76d9516190ac7444f7d69cf952c4cbdc086fdef2d6fc83856040516127bc929190918252602082015260400190565b60405180910390a35050505050505050565b6000816000036127f05760405162461bcd60e51b8152600401610d589061508c565b6000612806856127ff87611389565b60006136b3565b905060008184116128175783612819565b815b90508060000361283b5760405162461bcd60e51b8152600401610d589061508c565b6128458183614ec0565b6001600160a01b038088166000908152603d60205260409020919091556128b0907f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9167f00000000000000000000000025f2226b597e8f9514b3f68f00f494cf4f2864918784612b8c565b846001600160a01b0316866001600160a01b03167f9310ccfcb8de723f578a9e4282ea9f521f05ae40dc08f3068dfad528a65ee3c7836040516128f591815260200190565b60405180910390a395945050505050565b60006129128484611e71565b9050600019811461169f578181101561296d5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610d58565b61169f848484840361232a565b600061298584611389565b9050612993848260016136b3565b50826001600160a01b0316846001600160a01b031614612a9e5760006129b884611389565b90506129c6848260016136b3565b506001600160a01b0385166000908152603e602090815260409182902082518084019093525464ffffffffff8116808452600160281b9091046001600160d81b03169183019190915215612a9b57838303612a39576001600160a01b0386166000908152603e6020526040812055612a9b565b60208101516001600160d81b0316612a518585614ec0565b1015612a9b57612a618484614ec0565b6001600160a01b0387166000908152603e60205260409020805464ffffffffff166001600160b81b0392909216600160281b029190911790555b50505b61169f848484613909565b6000612ab482611389565b905080600003612b065760405162461bcd60e51b815260206004820152601b60248201527f494e56414c49445f42414c414e43455f4f4e5f434f4f4c444f574e00000000006044820152606401610d58565b60408051808201825264ffffffffff42811682526001600160d81b0380851660208085019182526001600160a01b0388166000818152603e9092529086902094519151909216600160281b0292169190911790915590517f8a05f911d8ab7fc50fec37ef4ba7f9bfcb1a3c191c81dcd824ad0946c4e20d659061214c9084815260200190565b6040516001600160a01b038085166024830152831660448201526064810182905261169f9085906323b872dd60e01b906084016122f3565b6001600160a01b038216612c0e5760405162461bcd60e51b8152602060048201526011602482015270494e56414c49445f44454c45474154454560781b6044820152606401610d58565b6000612c1982612cc5565b925050506000612c2885611389565b90506000612c368684612d04565b6001600160a01b03878116600090815260208690526040902080546001600160a01b0319169188169190911790559050612c7281868487613ab8565b846001600160a01b0316866001600160a01b03167fe8d51c8e11bd570db1734c8ec775785330e77007feed45c43b608ef33ff914bd86604051612cb59190615102565b60405180910390a3505050505050565b6000808080846001811115612cdc57612cdc615053565b03612cf157506006915060079050603f612cfd565b50604091506041905060425b9193909250565b6001600160a01b03808316600090815260208390526040812054909116806110c25783915050610f54565b605154600160d81b900460ff1615612d7c5760405162461bcd60e51b815260206004820152601060248201526f534c415348494e475f4f4e474f494e4760801b6044820152606401610d58565b80600003612d9c5760405162461bcd60e51b8152600401610d589061508c565b6000612da783611389565b90506000612dbf843084612dba60025490565b613cbc565b90508015612e42576001600160a01b0384166000908152603d6020526040902054612deb908290614f44565b6001600160a01b0385166000818152603d60209081526040918290209390935580519182529181018390527f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a76910160405180910390a15b6000612e4d846113a4565b9050612e846001600160a01b037f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae916873087612b8c565b612e8e8582613d7d565b846001600160a01b0316866001600160a01b03167f6c86f3fd5118b3aa8bb4f389a617046de0a3d3d477de1a1673d227f802f616dc8684604051612cb5929190918252602082015260400190565b6127108110612f2d5760405162461bcd60e51b815260206004820152601b60248201527f494e56414c49445f534c415348494e475f50455243454e5441474500000000006044820152606401610d58565b60508190556040518181527fb79c2d6c7f5c95eec9dc05affc0ed002620a4ec6d72b7b0744cc8638168c600a906020015b60405180910390a150565b604f8190556040518181527fbbf67247b5c97564e30ffc0a355e71c006836de7b9149e09e3d5d6054cb0335590602001612f5e565b600080805b83518110156130a4576000603c6000868481518110612fc457612fc4614f90565b602090810291909101810151516001600160a01b031682528101919091526040016000908120600181015481548851929450613032926001600160801b0380831692600160801b900416908a908890811061302157613021614f90565b602002602001015160400151613e48565b905061308386848151811061304957613049614f90565b602002602001015160200151828460020160008b6001600160a01b03166001600160a01b0316815260200190815260200160002054613f53565b61308d9085614f44565b93505050808061309c90614fc8565b915050612fa3565b509392505050565b60007f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae96001600160a01b03167f0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae96001600160a01b03161461314f5760405162461bcd60e51b815260206004820181905260248201527f5245574152445f544f4b454e5f49535f4e4f545f5354414b45445f544f4b454e6044820152606401610d58565b60006131658561315e87611389565b60016136b3565b905060008184116131765783613178565b815b90508015611a605761318b8630836127ce565b50611a60308683612d2f565b60408051600380825260808201909252600091816020015b60408051808201909152600080825260208201528152602001906001900390816131af579050509050604051806040016040528060008152602001876001600160a01b03168152508160008151811061320a5761320a614f90565b6020026020010181905250604051806040016040528060018152602001866001600160a01b03168152508160018151811061324757613247614f90565b6020026020010181905250604051806040016040528060028152602001856001600160a01b03168152508160028151811061328457613284614f90565b602002602001018190525061329881613f7f565b6132a183612edc565b6132aa82612f69565b611478670de0b6b3a7640000612222565b60005b8151811015611074576000603c60008484815181106132df576132df614f90565b6020026020010151604001516001600160a01b03166001600160a01b03168152602001908152602001600020905061335283838151811061332257613322614f90565b6020026020010151604001518285858151811061334157613341614f90565b60200260200101516020015161415b565b5082828151811061336557613365614f90565b60209081029190910101515181546fffffffffffffffffffffffffffffffff19166001600160801b0390911617815582518390839081106133a8576133a8614f90565b6020026020010151604001516001600160a01b03167f87fa03892a0556cb6b8f97e6d533a150d4d55fcbf275fff5fa003fa636bcc7fa8484815181106133f0576133f0614f90565b602090810291909101810151516040516001600160801b0390911681520160405180910390a2508061342181614fc8565b9150506132be565b60515460009061344990605290600160e01b900463ffffffff1684614213565b670de0b6b3a764000061345e87878787614320565b6134689190614f57565b611a609190614f6e565b60006001600160d81b038211156134db5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663136206269747360c81b6064820152608401610d58565b5090565b600064ffffffffff8211156134db5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526530206269747360d01b6064820152608401610d58565b806001600160d81b03166000036135935760405162461bcd60e51b81526020600482015260126024820152715a45524f5f45584348414e47455f5241544560701b6044820152606401610d58565b605180546001600160d81b0319166001600160d81b0383169081179091556040519081527fa9c433f9734baa3cf48b209454bb0ace054e191f677ba50e74b696c0d35ef26290602001612f5e565b6000613636826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166143fa9092919063ffffffff16565b80519091501561106457808060200190518101906136549190614fa6565b6110645760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610d58565b6000806136c5853086612dba60025490565b6001600160a01b0386166000908152603d6020526040812054919250906136ed908390614f44565b90508115611a60578315613717576001600160a01b0386166000908152603d602052604090208190555b604080516001600160a01b0388168152602081018490527f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a76910160405180910390a195945050505050565b6001600160a01b0382166137c25760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610d58565b6137ce82600083614409565b6001600160a01b038216600090815260208190526040902054818110156138425760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610d58565b6001600160a01b0383166000818152602081815260408083208686039055600280548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b60006001600160b81b038211156134db5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663834206269747360c81b6064820152608401610d58565b6001600160a01b03831661396d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610d58565b6001600160a01b0382166139cf5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610d58565b6139da838383614409565b6001600160a01b03831660009081526020819052604090205481811015613a525760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610d58565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a361169f565b826001600160a01b0316846001600160a01b0316031561169f57600080613ade83612cc5565b5090925090506001600160a01b03861615613bcf576001600160a01b0386166000908152602082905260408120548015613b5e576001600160a01b038816600090815260208590526040812090613b36600184614ec0565b8152602081019190915260400160002054600160801b90046001600160801b03169150613b6a565b613b6788611389565b91505b613b8084848a85613b7b8b82614ec0565b614588565b6001600160a01b0388167fa0a19463ee116110c9b282012d9b65cc5522dc38a9520340cbaf3142e550127f613bb58885614ec0565b87604051613bc4929190615110565b60405180910390a250505b6001600160a01b03851615611478576001600160a01b0385166000908152602082905260408120548015613c49576001600160a01b038716600090815260208590526040812090613c21600184614ec0565b8152602081019190915260400160002054600160801b90046001600160801b03169150613c55565b613c5287611389565b91505b613c6684848985613b7b8b82614f44565b6001600160a01b0387167fa0a19463ee116110c9b282012d9b65cc5522dc38a9520340cbaf3142e550127f613c9b8885614f44565b87604051613caa929190615110565b60405180910390a25050505050505050565b6001600160a01b038084166000908152603c602090815260408083209388168352600284019091528120549091908280613cf788858861415b565b9050808314613d71578615613d1457613d11878285613f53565b91505b6001600160a01b03808a1660008181526002870160205260409081902084905551918a16917fbb123b5c06d5408bbea3c4fef481578175cfb432e3b482c6186f02ed9086585b90613d689085815260200190565b60405180910390a35b50979650505050505050565b6001600160a01b038216613dd35760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610d58565b613ddf60008383614409565b8060026000828254613df19190614f44565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6000831580613e55575081155b80613e68575042836001600160801b0316145b80613e9c57507f000000000000000000000000000000000000000000000000000000012080ca63836001600160801b031610155b15613ea8575083611381565b60007f000000000000000000000000000000000000000000000000000000012080ca634211613ed75742613ef9565b7f000000000000000000000000000000000000000000000000000000012080ca635b90506000613f106001600160801b03861683614ec0565b90508684613f206012600a615208565b613f2a848a614f57565b613f349190614f57565b613f3e9190614f6e565b613f489190614f44565b979650505050505050565b6000613f616012600a615208565b613f6b8385614ec0565b613f759086614f57565b6110bf9190614f6e565b60005b81518110156110745760006001600160a01b031660456000848481518110613fac57613fac614f90565b602090810291909101810151518252810191909152604001600020546001600160a01b031614801561400e575060006001600160a01b0316828281518110613ff657613ff6614f90565b6020026020010151602001516001600160a01b031614155b61405a5760405162461bcd60e51b815260206004820152601b60248201527f41444d494e5f43414e4e4f545f42455f494e495449414c495a454400000000006044820152606401610d58565b81818151811061406c5761406c614f90565b6020026020010151602001516045600084848151811061408e5761408e614f90565b602002602001015160000151815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055508181815181106140de576140de614f90565b6020026020010151602001516001600160a01b03167f83a9ddad961dcb7c6894c9585a16ff7792c2ec8281256a3cc7303ae830152dcf83838151811061412657614126614f90565b60200260200101516000015160405161414191815260200190565b60405180910390a28061415381614fc8565b915050613f82565b6001820154825460009190600160801b90046001600160801b031642819003614186575090506110c2565b84546000906141a19084906001600160801b03168488613e48565b90508281146141f057600186018190556040518181526001600160a01b038816907f5777ca300dfe5bead41006fbce4389794dbc0ed8d6cccebfaf94630aa04184bc9060200160405180910390a25b85546001600160801b03428116600160801b029116178655925050509392505050565b600019820160009081526020849052604081205464ffffffffff16821061425e57506000198201600090815260208490526040902054600160281b90046001600160d81b03166110c2565b600060001984015b818111156142f75760028282030481036000818152602088815260409182902082518084019093525464ffffffffff8116808452600160281b9091046001600160d81b0316918301919091528690036142d157602001516001600160d81b031693506110c292505050565b805164ffffffffff168611156142e9578193506142f0565b6001820392505b5050614266565b5060009081526020949094525050604090912054600160281b90046001600160d81b0316919050565b6000438211156143695760405162461bcd60e51b815260206004820152601460248201527324a72b20a624a22fa12627a1a5afa72aa6a122a960611b6044820152606401610d58565b6001600160a01b0383166000908152602085905260408120549081900361439b5761439384611389565b915050611381565b6001600160a01b0384166000908152602087815260408083208380529091529020546001600160801b03168310156143d7576000915050611381565b6001600160a01b0384166000908152602087905260409020611acf90828561469e565b60606110bf84846000856147aa565b6053546001600160a01b031680156144e057806001600160a01b0316635b9c4cf1858561443588611389565b61443e88611389565b6040516001600160e01b031960e087901b1681526001600160a01b039485166004820152939092166024840152604483015260648201526084810185905260a401600060405180830381600087803b15801561449957600080fd5b505af19250505080156144aa575060015b6144e0573d8080156144d8576040519150601f19603f3d011682016040523d82523d6000602084013e6144dd565b606091505b50505b6001600160a01b038085166000908152603f6020526040808220548684168352912054908216911681614511578591505b6001600160a01b0381166145225750835b61452f8282866000613ab8565b6001600160a01b03808716600090815260426020526040808220548884168352912054908216911681614560578791505b6001600160a01b0381166145715750855b61457e8282886001613ab8565b5050505050505050565b6001600160a01b038316600090815260208581526040808320549188905290912043919081158015906145ea57506001600160801b0383168160006145ce600186614ec0565b81526020810191909152604001600020546001600160801b0316145b1561462e57838160006145fe600186614ec0565b8152602081019190915260400160002080546001600160801b03928316600160801b02921691909117905561457e565b6040805180820182526001600160801b038086168252868116602080840191825260008781529086905293909320915192518116600160801b02921691909117905561467b826001614f44565b6001600160a01b0387166000908152602089905260409020555050505050505050565b60001982016000908152602084905260408120546001600160801b031682106146eb57506000198201600090815260208490526040902054600160801b90046001600160801b03166110c2565b600060001984015b81811115614781576002828203048103600081815260208881526040918290208251808401909352546001600160801b03808216808552600160801b909204169183019190915286900361475957602001516001600160801b031693506110c292505050565b80516001600160801b03168611156147735781935061477a565b6001820392505b50506146f3565b5060009081526020949094525050604090912054600160801b90046001600160801b0316919050565b60608247101561480b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610d58565b600080866001600160a01b031685876040516148279190615214565b60006040518083038185875af1925050503d8060008114614864576040519150601f19603f3d011682016040523d82523d6000602084013e614869565b606091505b5091509150613f4887838387606083156148e45782516000036148dd576001600160a01b0385163b6148dd5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610d58565b5081611381565b61138183838151156148f95781518083602001fd5b8060405162461bcd60e51b8152600401610d5891906149a4565b6001600160a01b038116811461113057600080fd5b6000806040838503121561493b57600080fd5b823561494681614913565b946020939093013593505050565b60005b8381101561496f578181015183820152602001614957565b50506000910152565b60008151808452614990816020860160208601614954565b601f01601f19169290920160200192915050565b6020815260006110c26020830184614978565b6000602082840312156149c957600080fd5b81356110c281614913565b6000602082840312156149e657600080fd5b5035919050565b600080600060608486031215614a0257600080fd5b8335614a0d81614913565b92506020840135614a1d81614913565b929592945050506040919091013590565b60008060408385031215614a4157600080fd5b8235614a4c81614913565b91506020830135614a5c81614913565b809150509250929050565b803560028110614a7657600080fd5b919050565b60008060408385031215614a8e57600080fd5b8235614a9981614913565b9150614aa760208401614a67565b90509250929050565b803560ff81168114614a7657600080fd5b60008060008060008060c08789031215614ada57600080fd5b8635614ae581614913565b95506020870135945060408701359350614b0160608801614ab0565b92506080870135915060a087013590509295509295509295565b600060208284031215614b2d57600080fd5b813563ffffffff811681146110c257600080fd5b60008060008060808587031215614b5757600080fd5b8435614b6281614913565b93506020850135614b7281614913565b93969395505050506040820135916060013590565b600080600080600060a08688031215614b9f57600080fd5b8535614baa81614913565b94506020860135614bba81614913565b93506040860135614bca81614913565b94979396509394606081013594506080013592915050565b60008060408385031215614bf557600080fd5b823591506020830135614a5c81614913565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff81118282101715614c4057614c40614c07565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715614c6f57614c6f614c07565b604052919050565b60006020808385031215614c8a57600080fd5b823567ffffffffffffffff80821115614ca257600080fd5b818501915085601f830112614cb657600080fd5b813581811115614cc857614cc8614c07565b614cd6848260051b01614c46565b81815284810192506060918202840185019188831115614cf557600080fd5b938501935b82851015613d715780858a031215614d125760008081fd5b614d1a614c1d565b85356001600160801b0381168114614d325760008081fd5b81528587013587820152604080870135614d4b81614913565b9082015284529384019392850192614cfa565b600080600060608486031215614d7357600080fd5b8335614d7e81614913565b925060208401359150614d9360408501614a67565b90509250925092565b600080600080600080600060e0888a031215614db757600080fd5b8735614dc281614913565b96506020880135614dd281614913565b95506040880135945060608801359350614dee60808901614ab0565b925060a0880135915060c0880135905092959891949750929550565b600080600060608486031215614e1f57600080fd5b8335614e2a81614913565b95602085013595506040909401359392505050565b600080600080600080600060e0888a031215614e5a57600080fd5b8735614e6581614913565b9650614dd260208901614a67565b60208082526019908201527f43414c4c45525f4e4f545f534c415348494e475f41444d494e00000000000000604082015260600190565b634e487b7160e01b600052601160045260246000fd5b81810381811115610f5457610f54614eaa565b600181811c90821680614ee757607f821691505b602082108103614f0757634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526017908201527f43414c4c45525f4e4f545f434c41494d5f48454c504552000000000000000000604082015260600190565b80820180821115610f5457610f54614eaa565b8082028115828204841417610f5457610f54614eaa565b600082614f8b57634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b600060208284031215614fb857600080fd5b815180151581146110c257600080fd5b600060018201614fda57614fda614eaa565b5060010190565b61190160f01b81526002810192909252602282015260420190565b602080825260119082015270494e56414c49445f5349474e415455524560781b604082015260600190565b60208082526012908201527124a72b20a624a22fa2ac2824a920aa24a7a760711b604082015260600190565b634e487b7160e01b600052602160045260246000fd5b600063ffffffff80831681810361508257615082614eaa565b6001019392505050565b6020808252601390820152721253959053125117d6915493d7d05353d55395606a1b604082015260600190565b6001600160d81b038281168282160390808211156150d9576150d9614eaa565b5092915050565b600281106150fe57634e487b7160e01b600052602160045260246000fd5b9052565b60208101610f5482846150e0565b828152604081016110c260208301846150e0565b600181815b8085111561515f57816000190482111561514557615145614eaa565b8085161561515257918102915b93841c9390800290615129565b509250929050565b60008261517657506001610f54565b8161518357506000610f54565b816001811461519957600281146151a3576151bf565b6001915050610f54565b60ff8411156151b4576151b4614eaa565b50506001821b610f54565b5060208310610133831016604e8410600b84101617156151e2575081810a610f54565b6151ec8383615124565b806000190482111561520057615200614eaa565b029392505050565b60006110c28383615167565b60008251615226818460208701614954565b919091019291505056fea2646970667358221220eca7538023765a4de548dace73c5919366f9605051f5141240ca82e0c4ea703c64736f6c63430008110033

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

0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae90000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000000000000000000000000000000000000002a30000000000000000000000000025f2226b597e8f9514b3f68f00f494cf4f286491000000000000000000000000ee56e2b3d491590b5b31738cc34d5232f378a8d500000000000000000000000000000000000000000000000000000000bc180c38

-----Decoded View---------------
Arg [0] : stakedToken (address): 0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9
Arg [1] : rewardToken (address): 0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9
Arg [2] : unstakeWindow (uint256): 172800
Arg [3] : rewardsVault (address): 0x25F2226B597E8F9514B3F68F00f494cF4f286491
Arg [4] : emissionManager (address): 0xEE56e2B3D491590B5b31738cC34d5232F378a8D5
Arg [5] : distributionDuration (uint128): 3155692600

-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9
Arg [1] : 0000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9
Arg [2] : 000000000000000000000000000000000000000000000000000000000002a300
Arg [3] : 00000000000000000000000025f2226b597e8f9514b3f68f00f494cf4f286491
Arg [4] : 000000000000000000000000ee56e2b3d491590b5b31738cc34d5232f378a8d5
Arg [5] : 00000000000000000000000000000000000000000000000000000000bc180c38


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

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