CRO Price: $0.09 (-1.38%)

Contract

0x211b580107AE76FeD8938a5ED04FF0fb940Fb5dB

Overview

CRO Balance

Cronos Chain LogoCronos Chain LogoCronos Chain Logo0 CRO

CRO Value

$0.00

Multichain Info

No addresses found
Amount:Between 1-10
Reset Filter

Transaction Hash
Method
Block
From
To

There are no matching entries

Update your filters to view other transactions

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CrooksStakingV2

Compiler Version
v0.8.26+commit.8a97fa7a

Optimization Enabled:
Yes with 125 runs

Other Settings:
paris EvmVersion
File 1 of 33 : CrooksStakingV2.sol
/**                                                                                        
                                                                                                                      
 ________  ________  ________  ________  ___  __    ________      
|\   ____\|\   __  \|\   __  \|\   __  \|\  \|\  \ |\   ____\     
\ \  \___|\ \  \|\  \ \  \|\  \ \  \|\  \ \  \/  /|\ \  \___|_    
 \ \  \    \ \   _  _\ \  \\\  \ \  \\\  \ \   ___  \ \_____  \   
  \ \  \____\ \  \\  \\ \  \\\  \ \  \\\  \ \  \\ \  \|____|\  \  
   \ \_______\ \__\\ _\\ \_______\ \_______\ \__\\ \__\____\_\  \ 
    \|_______|\|__|\|__|\|_______|\|_______|\|__| \|__|\_________\
                                                      \|_________|
                                                                                                                                                                    
      
      Crooks(TM) 
      Website: https://crooks.finance/
      Telegram: https://t.me/crookstoken
      X: https://x.com/crooksfinance


 * @title Crooks Staking V2
 * @author ETHERCODE - Exit : https://www.ethercode.dev/ 
 * @notice Crooks Staking V2 allows investors to stake $CRKS & CRKL NFTs to earn rewards.

 */

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {IERC721ReceiverUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import {Crooks} from "./CRKS.sol";
import {Nuts} from "./NUTS.sol";
import {ICrooksLegends} from "./interfaces/ICrooksLegends.sol";
import {StakingLogics} from "./StakingLogics.sol";

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract CrooksStakingV2 is Initializable, UUPSUpgradeable, OwnableUpgradeable, PausableUpgradeable, ReentrancyGuardUpgradeable, IERC721ReceiverUpgradeable{

     /* Custom Errors */

     error CrksStak__InvalidAmount();
     error CrksStak__InvalidAddress();
     error CrksStak__TransferFailed();
     error CrksStak__NotEnoughBalance();
     error CrksStak__NotEnoughContractBalance();
     error CrksStak__NotEnoughAllowance();
     error CrksStak__InvalidStakingOption();
     error CrksStak__ClaimRewardsFirst(uint256 toClaim);
     error CrksStak__StakingPeriodNotOver();
     error CrksStak__NotTheNftOwner(uint16);
     error CrksStak__ClaimRankRewardsFirst(uint256 croRew, uint256 nutsRew);
     error CrksStak__ZeroRewardsToClaim();
     error CrksStak__PartnershipExists();
     error CrksStak__PartnershipNotExists();
     error CrksStak__InvalidERC20token();
     error CrksStak__NoNftStakes();

     /* Type Declarations */

     struct StakingRules {
          uint256 maxAmount; // Maximum amount of CRKS that can be staked
          uint8 minStakingPeriod; // in months
          uint16 maxStakingPeriod; // in months
          uint24 APRxMonths; // Annual APR that needs to multiply per month staked -> in 3 decimal percentage (e.g. 500 for 0.5%)
          uint32 lastChange; // timestamp of the last change
     }

     struct CrksStake {
          uint256 amount;
          uint32 stakedAt;
          uint8 stakedFor;
          uint256 stakedUntil;
          uint32 infoIndex;
     }

     struct CrksClaim {
          uint256 totClaimed;
          uint32 lastClaimTime;
          uint256 totCompounded;
          uint32 lastCompTime;
          uint32 lastInfoIndex;
     }

     struct Rank {
          uint256 minStakedAmount; // Required minimum CRKS staked amount to achieve this rank
          uint16 minLegendsAmount; // Required minimum amount of legends to achieve this rank
          uint24 aprBonus; // Annual APR bonus for this rank // 3 Decimals
          uint8 rankDistribution; // Rank distribution percentage // 0 Decimals
     }

     struct AlignBonus {
          uint256 crksReq; // Align Requirements
          uint16 crklReq;
          uint24 aprBonus;  // Align Annual APR Bonus //3 Decimals
     }

     struct NftStake {
          uint16 amount;
          uint16[] nftIds;
          uint32 lastChange;
     }

     struct UltimateBonus {
          address ultimateCrook; // Address of the monthly ultimate crook
          uint8 aprUC; // APR bonus for the ultimate crook // 0 Decimals
     }

     struct UserUltimate {
          bool uC; // Ultimate Crook
          uint32 fromTimestamp;
          uint32 toTimestamp;
     }

     struct RankRewardsDailyDistr {
          uint32 timestamp; // Last variables saving timestamp
          uint256 croRewards; // Rewards to distribute Daily
          uint256 nutsRewards; // "" "" 
          uint256[] pttRewards; // "" ""
          uint16 nOfMembers; // Number of members that day
          uint16 nOfHustlers;
          uint16 nOfStreetSoldiers;
          uint16 nOfEnforcers;
          uint16 nOfOfficers;
          uint16 nOfCaptains;
          uint16 nOfGenerals;
          uint16 nOfGangLeaders;
          uint16 nOfBosses;
     }

     struct RankRewardsClaim {
          uint256 croClaimed;
          uint256 nutsClaimed;
          uint256[] pttClaimed;
          uint32 lastClaimTime;
     }

     /* State Variables */

     uint256 private constant _ONE_MONTH = 2629743; // in seconds
     uint256 private constant _ONE_YEAR = 31556916; // 12 months in seconds
     uint256 private constant _APR_DENOMINATOR = 1000; // 3 Decimals
     uint256 private constant _NFT_QUALITY_DENOMINATOR = 100000000000000000000;

     Crooks private _crks;
     Nuts private _nuts;
     ICrooksLegends private _crooksLegends;
     StakingLogics private _stakingLogics;
     address[] private _partnerships;

     uint256 public crksTotalStaked;
     uint256 public crksBalanceForRewards;
     uint256 public totalCrksRewarded;
     uint256 public totalCroRewarded;
     uint256 public totalNutsRewarded;
     uint32 public infoIndex;
     uint8[] public contractBalancePercForRankRew;
     uint8 public uncapOnePercAPRinUSDT;
     uint24 public cappedPercAPR;

     AlignBonus private _alignBonus;
     UltimateBonus private _ultimateBonus;
     RankRewardsDailyDistr[] private _rankRewardsDailyDistr;

     mapping(uint32 => StakingRules) private _stakingRule;
     mapping(address => CrksStake) private _crksStakes;
     mapping(address => CrksClaim) private _crksClaims;
     mapping(string => Rank) private _rank;
     mapping(address => NftStake[]) private _nftStakes;
     mapping(address => UserUltimate) private _userUltimate;     
     mapping(address => RankRewardsClaim) private _rankRewClaim;
     mapping(string => uint16) private _rankCounters;
     mapping(address => uint256) public userUncappedAPR;

     event CrksStaked(address indexed account, uint256 amount, uint32 stakedFor);
     event CrksUnstaked(address indexed account, uint256 amount);
     event CrksClaimed(address indexed account, uint256 amount);
     event CrksCompounded(address indexed account, uint256 amount);
     event CrksStakeOverwritten(address indexed account, uint256 amount, uint32 stakedFor);
     event CrklNftStaked(address indexed account, uint16 amount, uint16[] nftIds);
     event CrklNftUnstaked(address indexed account, uint16 amount, uint16[] nftIds);
     event RankRewardsClaimed(address indexed account, uint256 croRewards, uint256 nutsRewards, uint256[] pttRewards);
     event AprUncapped(address indexed account, uint256 uncappedApr);

     /* Initializer */

     /// @custom:oz-upgrades-unsafe-allow constructor
     constructor() {
          _disableInitializers();
     }

     function initialize(address crooksAddress, address nutsAddress, address legendsAddress) public initializer {

          __Ownable_init();
          __Pausable_init();
          __ReentrancyGuard_init();
          __UUPSUpgradeable_init();

          _crks = Crooks(payable(crooksAddress));
          _nuts = Nuts(payable(nutsAddress));
          _crooksLegends = ICrooksLegends(legendsAddress);
          infoIndex = 0;
          crksTotalStaked = 0;
          crksBalanceForRewards = 0;
          totalCrksRewarded = 0;
          totalCroRewarded = 0;
          totalNutsRewarded = 0;
          // % of the contract balance for the Rank Rewards
          contractBalancePercForRankRew = [5, 5, 5]; // 5% of CRO, NUTS, PTT
          // 1% APR uncapped with 10 USDT of CRKS
          uncapOnePercAPRinUSDT = 10;
          cappedPercAPR = 100000; // over 100% Yearly, the APR is capped - 3 Decimals
          
          StakingRules storage info = _stakingRule[infoIndex];
          info.maxAmount = 2500000 ether;
          info.minStakingPeriod = 1;
          info.maxStakingPeriod = 48;
          info.APRxMonths = 500; // 0.5% (* Staking Months)
          info.lastChange = uint32(block.timestamp);

          _alignBonus = AlignBonus(1000 ether, 1, 100); // 1000 CRKS staked & 1 Legend // 0.1% APR bonus
          _ultimateBonus = UltimateBonus(address(0), 25); // 25% APR bonus for the ultimate crook

          _rankCounters["PROSPECT"] = 0;
          _rankCounters["MEMBER"] = 0;
          _rankCounters["HUSTLER"] = 0;
          _rankCounters["STREET SOLDIER"] = 0;
          _rankCounters["ENFORCER"] = 0;
          _rankCounters["OFFICER"] = 0;
          _rankCounters["CAPTAIN"] = 0;
          _rankCounters["GENERAL"] = 0;
          _rankCounters["GANG LEADER"] = 0;
          _rankCounters["BOSS"] = 0;

          _rank["PROSPECT"] = Rank(0, 0, 0, 0);                 // 0 CRKS staked & 0 Legends                     // 0% APR bonus + Rank distribution 0%
          _rank["MEMBER"] = Rank(10000 ether, 1, 1000, 10);          // 10,000 CRKS staked & 1 Legend                  // 1% APR bonus +  Rank distribution 10%
          _rank["HUSTLER"] = Rank(20000 ether, 2, 2000, 10);         // 20,000 CRKS staked & 2 Legends                 // 2% APR bonus +  Rank distribution 10%
          _rank["STREET SOLDIER"] = Rank(30000 ether, 3, 5000, 10);  // 30,000 CRKS staked & 3 Legends                 // 5% APR bonus +  Rank distribution 10%
          _rank["ENFORCER"] = Rank(50000 ether, 5, 10000, 10);        // 50,000 CRKS staked & 5 Legends                 // 10% APR bonus +  Rank distribution 10%
          _rank["OFFICER"] = Rank(100000 ether, 10, 15000, 10);       // 100,000 CRKS staked & 10 Legends               // 15% APR bonus + Rank distribution 10%
          _rank["CAPTAIN"] = Rank(250000 ether, 25, 20000, 10);       // 250,000 CRKS staked & 25 Legends               // 20% APR bonus + Rank distribution 10%
          _rank["GENERAL"] = Rank(500000 ether, 50, 30000, 10);       // 500,000 CRKS staked & 50 Legends               // 30% APR bonus + Rank distribution 10%
          _rank["GANG LEADER"] = Rank(1000000 ether, 100, 40000, 15); // 1,000,000 CRKS staked & 100 Legends            // 40% APR bonus + Rank distribution 15%
          _rank["BOSS"] = Rank(2500000 ether, 250, 50000, 15);        // 2,500,000 CRKS staked & 250 Legends            // 50% APR bonus + Rank distribution 15%
     }   

     receive() external payable {}

     /* External Functions */

     /**
      * @dev Stake CRKS tokens for a specified period.
      * @param amount The amount of CRKS tokens to stake.
      * @param stakedFor The period (in months) for which the tokens are staked.
      */
     function stakeCrks(uint256 amount, uint8 stakedFor) external payable whenNotPaused nonReentrant {
          // Set up
          StakingRules memory info = _stakingRule[infoIndex];
          // Checks
          if(amount == 0 || amount > info.maxAmount) {revert CrksStak__InvalidAmount();}
          if(stakedFor < info.minStakingPeriod || stakedFor > info.maxStakingPeriod) {revert CrksStak__InvalidStakingOption();}
          if(amount > _crks.balanceOf(msg.sender)) {revert CrksStak__NotEnoughBalance();}
               // Allowance check (Need to approve the contract to spend the amount first)
          if(amount > _crks.allowance(msg.sender, address(this))) {revert CrksStak__NotEnoughAllowance();}

          CrksStake storage stake = _crksStakes[msg.sender];
          // Ranks Counters Update
          uint256 NftHistLength = _nftStakes[msg.sender].length;
          if (NftHistLength > 0) {
               NftStake memory nftStake = getLastNftStake(msg.sender);
               string memory rank = _stakingLogics.calcRank(stake.amount, nftStake.amount);
               _rankCounters[rank]--; // Decrease the current rank counter
          }
          
          // Check if the user has already staked
          if(stake.amount > 0) {
               // Check if total amount staked is less than the max amount
               if(stake.amount + amount > info.maxAmount) {revert CrksStak__InvalidAmount();}
               // First claim the rewards
               uint256 croRew;
               uint256 nutsRew;
               uint256 rewToClaim = _stakingLogics.getCrksRewards(msg.sender);
               if(rewToClaim > 0) {revert CrksStak__ClaimRewardsFirst(rewToClaim);}
               (croRew, nutsRew, ) = _stakingLogics.getRankRewards(msg.sender);
               if(croRew > 0 || nutsRew > 0) {revert CrksStak__ClaimRankRewardsFirst(croRew, nutsRew);}
               // Update the stake
               stake.amount += amount;
               stake.stakedAt = uint32(block.timestamp);
               stake.stakedUntil = stake.stakedAt + stake.stakedFor * _ONE_MONTH; // Reset the staking period
               stake.infoIndex = infoIndex;
               // Transfer CRKS from user to contract
               if(!_crks.transferFrom(msg.sender, address(this), amount)) {revert CrksStak__TransferFailed();}
               // Emit event
               emit CrksStakeOverwritten(msg.sender, amount, stakedFor); 
          }  

          // If the user has not staked before
          else {
               // Update the stake
               stake.amount = amount;
               stake.stakedAt = uint32(block.timestamp);
               stake.stakedFor = stakedFor;
               stake.stakedUntil = stake.stakedAt + stakedFor * _ONE_MONTH;
               stake.infoIndex = infoIndex;
               // Transfer CRKS from user to contract
               if(!_crks.transferFrom(msg.sender, address(this), amount)) {revert CrksStak__TransferFailed();}
               // Emit event
               emit CrksStaked(msg.sender, amount, stakedFor);
          }

          // Ranks Counters Update
          if (NftHistLength > 0) {
               NftStake memory nftStake = getLastNftStake(msg.sender);
               string memory rank = _stakingLogics.calcRank(stake.amount, nftStake.amount);
               _rankCounters[rank]++; // Increase the new rank counter
          }

          // Update the total staked amount
          crksTotalStaked += amount;
     }

     /**
      * @dev Unstake CRKS tokens after the staking period is over.
      */
     function unstakeCrks() external whenNotPaused nonReentrant {
          // Set up
          uint256 croRew;
          uint256 nutsRew;
          CrksStake storage stake = _crksStakes[msg.sender];
          uint256 rewToClaim = _stakingLogics.getCrksRewards(msg.sender);
          (croRew, nutsRew, ) = _stakingLogics.getRankRewards(msg.sender);
          // Checks
          if(stake.amount == 0) {revert CrksStak__NotEnoughBalance();}
          if(stake.amount > _crks.balanceOf(address(this))) {revert CrksStak__NotEnoughContractBalance();}
          if(stake.stakedUntil > uint32(block.timestamp)) {revert CrksStak__StakingPeriodNotOver();}
               // First claim the rewards
          if(rewToClaim > 0) {revert CrksStak__ClaimRewardsFirst(rewToClaim);}
          if(croRew > 0 || nutsRew > 0) {revert CrksStak__ClaimRankRewardsFirst(croRew, nutsRew);}
          // Ranks Counters Update
          uint256 NftHistLength = _nftStakes[msg.sender].length;
          if (NftHistLength > 0) {
               NftStake memory nftStake = getLastNftStake(msg.sender);
               string memory rank = _stakingLogics.calcRank(stake.amount, nftStake.amount);
               _rankCounters[rank]--; // Decrease the current rank counter
          }
          // Set the amount
          uint256 amount = stake.amount;
          // Reset the stake
          stake.amount = 0;
          stake.stakedAt = 0;
          stake.stakedFor = 0;
          stake.stakedUntil = 0;
          stake.infoIndex = 0;
          // Update the total staked amount
          crksTotalStaked -= amount;
          // Transfer CRKS from contract to user
          if(!_crks.transfer(msg.sender, amount)) {revert CrksStak__TransferFailed();}
          // Emit event
          emit CrksUnstaked(msg.sender, amount);
     }

     /**
      * @dev Claim and optionally compound CRKS rewards.
      * @param compoundPerc The percentage of rewards to compound.
      */
     function claimAndCompCrks(uint8 compoundPerc) external whenNotPaused nonReentrant {
          // Set up
          CrksClaim storage claim = _crksClaims[msg.sender];
          CrksStake storage stake = _crksStakes[msg.sender];
          UserUltimate storage ultimate = _userUltimate[msg.sender];
          uint256 rewToClaim = _stakingLogics.getCrksRewards(msg.sender);
          // Checks
          if(rewToClaim == 0) {revert CrksStak__ZeroRewardsToClaim();}
          if(compoundPerc > 100) {revert CrksStak__InvalidAmount();}
          if(rewToClaim > crksBalanceForRewards) {revert CrksStak__NotEnoughContractBalance();}

          // Check if the user want to compound the rewards
          if(compoundPerc > 0) {
               // First claim the rewards
               uint256 croRew;
               uint256 nutsRew;
               (croRew, nutsRew, ) = _stakingLogics.getRankRewards(msg.sender);
               if(croRew > 0 || nutsRew > 0) {revert CrksStak__ClaimRankRewardsFirst(croRew, nutsRew);}
               // Ranks Counters Update
               uint256 NftHistLength = _nftStakes[msg.sender].length;
               if (NftHistLength > 0) {
                    NftStake memory nftStake = getLastNftStake(msg.sender);
                    string memory rank = _stakingLogics.calcRank(stake.amount, nftStake.amount);
                    _rankCounters[rank]--; // Decrease the current rank counter
               }
               // Calculate the amount to compound
               uint256 amountToCompound = rewToClaim * compoundPerc / 100;
               // Check if the amount to compound + stake amount is less than the max amount
               if(amountToCompound + stake.amount > _stakingRule[infoIndex].maxAmount) {revert CrksStak__InvalidAmount();}
               // Update the reward to claim
               rewToClaim -= amountToCompound;
               // Update the claim
               claim.totCompounded += amountToCompound;
               claim.lastCompTime = uint32(block.timestamp);
               // Add the amount to the stake
               stake.amount += amountToCompound;
               // Update the balance for rewards
               crksBalanceForRewards -= amountToCompound;
               // Update Crooks Total Staked
               crksTotalStaked += amountToCompound;

               // Ranks Counters Update
               if (NftHistLength > 0) {
                    NftStake memory nftStake = getLastNftStake(msg.sender);
                    string memory rank = _stakingLogics.calcRank(stake.amount, nftStake.amount);
                    _rankCounters[rank]++; // Increase the new rank counter
               }
               // Emit event
               emit CrksCompounded(msg.sender, amountToCompound);
          }
          // Check if there are rewards to claim
          if(rewToClaim > 0) {
               // Update the claim
               claim.totClaimed += rewToClaim;
               claim.lastClaimTime = uint32(block.timestamp);
               // Update the balance for rewards
               crksBalanceForRewards -= rewToClaim;
               // Transfer CRKS from contract to user
               if(!_crks.transfer(msg.sender, rewToClaim)) {revert CrksStak__TransferFailed();}
               // Emit event
               emit CrksClaimed(msg.sender, rewToClaim);
          }

          // Check if the user is the Ultimate Crook and time is over
          if(ultimate.uC && uint32(block.timestamp) >= ultimate.toTimestamp) {
               // Reset the Ultimate Crook
               ultimate.uC = false;
               ultimate.fromTimestamp = 0;
               ultimate.toTimestamp = 0;
          }

          // Update the total CRKS rewarded
          totalCrksRewarded += rewToClaim;
     }
     
     /**
      * @dev Stake CRKL NFTs.
      * @param nftIds The IDs of the NFTs to stake.
      */
     function stakeNft(uint16[] memory nftIds) external whenNotPaused nonReentrant {
          // Set up
          uint16 nftAmount = uint16(nftIds.length);
          uint256 stakingLength = _nftStakes[msg.sender].length;
          uint256 crksAmount = _crksStakes[msg.sender].amount;
          // Checks
          if(nftAmount == 0) {revert CrksStak__InvalidAmount();}
               // Check if the user is the owner of the NFTs
          for(uint16 i = 0; i < nftAmount; i++) {
               if(_crooksLegends.ownerOf(nftIds[i]) != msg.sender) {revert CrksStak__NotTheNftOwner(nftIds[i]);}
          }
               //Check if the user approved the contract to spend all the NFTs
          if(!_crooksLegends.isApprovedForAll(msg.sender, address(this))) {revert CrksStak__NotEnoughAllowance();}

          // Ranks Counters Update
          if (stakingLength > 0) {
               NftStake memory nftStake = getLastNftStake(msg.sender);
               string memory rank = _stakingLogics.calcRank(crksAmount, nftStake.amount);
               _rankCounters[rank]--; // Decrease the current rank counter
          }

          // If the user has never staked NFTs before
          if(stakingLength == 0) {
               // Create the NftStake
               NftStake memory nftStake = NftStake(nftAmount, nftIds, uint32(block.timestamp));
               // Add the NftStake to the user
               _nftStakes[msg.sender].push(nftStake);
          } else {
               // Update the NftStake
               NftStake memory nftStake = _nftStakes[msg.sender][stakingLength - 1];
               nftStake.amount += nftAmount;
               nftStake.lastChange = uint32(block.timestamp);
                    // Add the nftIds to the array
               uint16[] memory oldNftIds = nftStake.nftIds;
               uint16[] memory newNftIds = new uint16[](oldNftIds.length + nftAmount);
               // Copy old NFTs
               for(uint i = 0; i < oldNftIds.length; i++){
                    newNftIds[i] = oldNftIds[i];
               }
               // Add new NFTs
               for(uint i = 0; i < nftAmount; i++){
                    newNftIds[oldNftIds.length + i] = nftIds[i];
               }
               // Update the NftStake
               nftStake.nftIds = newNftIds;
               // Push the updated NftStake
               _nftStakes[msg.sender].push(nftStake);
          }

          // Ranks Counters Update
          if (_nftStakes[msg.sender].length > 0) {
               NftStake memory nftStake = getLastNftStake(msg.sender);
               string memory rank = _stakingLogics.calcRank(crksAmount, nftStake.amount);
               _rankCounters[rank]++; // Increase the new rank counter
          }

          // Transfer the NFTs from user to contract
          for(uint16 i = 0; i < nftAmount; i++) {
               _crooksLegends.safeTransferFrom(msg.sender, address(this), nftIds[i]);
          }
          // Emit event
          emit CrklNftStaked(msg.sender, nftAmount, nftIds);
     }

     /**
      * @dev Unstake CRKL NFTs.
      * @param ids The IDs of the NFTs to unstake.
      */
     function unstakeNft(uint16[] memory ids) external whenNotPaused nonReentrant {
          // Set up
          uint16 nftAmount = uint16(ids.length);
          uint16 stakingLength = uint16(_nftStakes[msg.sender].length);
          uint256 crksAmount = _crksStakes[msg.sender].amount;
          uint16[] memory nftIds;
          uint16[] memory newNftIds;
          bool found;
          // Checks
          if(nftAmount == 0) {revert CrksStak__InvalidAmount();}
          // Memory the nft struct
          NftStake memory nftStake = _nftStakes[msg.sender][stakingLength - 1];
          // Check if the user has NFTs to unstake
          if(nftStake.amount == 0) {revert CrksStak__NotEnoughBalance();}

          // Ranks Counters Update
          if (stakingLength > 0) {
               string memory rank = _stakingLogics.calcRank(crksAmount, nftStake.amount);
               _rankCounters[rank]--; // Decrease the current rank counter
          }

          // Transfer the NFTs from contract to user
          nftIds = nftStake.nftIds;
          for(uint i = 0; i < ids.length; i++){
               found = false;
               for(uint j = 0; j < nftIds.length; j++){
                    if(ids[i] == nftIds[j]){
                    found = true;
                    nftIds[j] = nftIds[nftIds.length - (1 + i)];
                    _crooksLegends.safeTransferFrom(address(this), msg.sender, ids[i]);
                    break;
                    }
               }
               if(!found) { revert CrksStak__NotTheNftOwner(ids[i]); }
          }
          // Create new nft option array
          newNftIds = new uint16[](nftIds.length - ids.length);
          if (newNftIds.length != 0) {
               for(uint256 i = 0; i < newNftIds.length; i++){
                    newNftIds[i] = nftIds[i];
               }
          }

          // Update the NftStake
          nftStake.amount -= nftAmount;
          nftStake.nftIds = newNftIds;
          nftStake.lastChange = uint32(block.timestamp);
          // Push the updated NftStake
          _nftStakes[msg.sender].push(nftStake);

          // Ranks Counters Update
          if (_nftStakes[msg.sender].length > 0) {
               NftStake memory nftStak = getLastNftStake(msg.sender);
               string memory rank = _stakingLogics.calcRank(crksAmount, nftStak.amount);
               _rankCounters[rank]++; // Increase the new rank counter
          }

          // Emit event
          emit CrklNftUnstaked(msg.sender, nftAmount, ids);
     }

     /**
      * @dev Claim rank rewards.
      */
     function claimRankRewards() external whenNotPaused nonReentrant {
          // Set up
          RankRewardsClaim storage claim = _rankRewClaim[msg.sender];
          uint256 croRew;
          uint256 nutsRew;
          uint256[] memory pttRew = new uint256[](_partnerships.length);
          (croRew, nutsRew, pttRew) = _stakingLogics.getRankRewards(msg.sender);
          // Checks
          if(croRew == 0 && nutsRew == 0 && pttRew.length == 0) {revert CrksStak__ZeroRewardsToClaim();}
          if(croRew > (address(this)).balance) {revert CrksStak__NotEnoughContractBalance();}
          if(nutsRew > _nuts.balanceOf(address(this))) {revert CrksStak__NotEnoughContractBalance();}

          // Update the claim
          claim.croClaimed += croRew;
          claim.nutsClaimed += nutsRew;
          claim.lastClaimTime = uint32(block.timestamp);
          // Transfer the rewards
          if(croRew > 0) {
               // Update total CRO rewarded
               totalCroRewarded += croRew;
               // Transfer ETH
               (bool success, ) = msg.sender.call{value: croRew}("");
               if(!success) {revert CrksStak__TransferFailed();}
          }
          if(nutsRew > 0) {
               // Update total NUTS rewarded
               totalNutsRewarded += nutsRew;
               // Transfer NUTS
               if(!_nuts.transfer(msg.sender, nutsRew)) {revert CrksStak__TransferFailed();}
          }
          if(pttRew.length > 0) {
               // Send the rewards for each partnership
               for(uint i = 0; i < _partnerships.length; i++) {
                    if(_partnerships[i] != address(0)) {
                         IERC20 ptt = IERC20(_partnerships[i]);
                         // Check if pttClaimed.length is less than _partnerships.length, and if so, add the missing elements
                         if(claim.pttClaimed.length < _partnerships.length) {
                              for(uint j = claim.pttClaimed.length; j < _partnerships.length; j++) {
                                   claim.pttClaimed.push(0);
                              }
                         }
                         claim.pttClaimed[i] += pttRew[i];
                         if(!ptt.transfer(msg.sender, pttRew[i])) {revert CrksStak__TransferFailed();}
                    }
               }
          }

          // Emit event
          emit RankRewardsClaimed(msg.sender, croRew, nutsRew, pttRew);
     }

     /**
      * @dev Uncap the APR for the user.
      * @param aprPerc The APR percentage to uncap (3 decimals) - e.g. 1000 for 1%.
      * @param crksAmounToUncap The amount of CRKS to uncap.
      */
     function uncapApr(uint256 aprPerc, uint256 crksAmounToUncap) external whenNotPaused nonReentrant {
          // Checks
          if(crksAmounToUncap > _crks.balanceOf(msg.sender)) {revert CrksStak__NotEnoughBalance();}
          if(crksAmounToUncap > _crks.allowance(msg.sender, address(this))) {revert CrksStak__NotEnoughAllowance();}
          if(crksAmounToUncap < _crks.getCrksAmountToUncapApr(aprPerc, uncapOnePercAPRinUSDT)) {revert CrksStak__InvalidAmount();}
          // Update the uncapped APR
          userUncappedAPR[msg.sender] += aprPerc;
          // Update the balance for rewards
          crksBalanceForRewards += crksAmounToUncap;
          // Transfer the amount
          if(!_crks.transferFrom(msg.sender, address(this), crksAmounToUncap)) {revert CrksStak__TransferFailed();}
          // Emit event
          emit AprUncapped(msg.sender, aprPerc);
     }

     /* Setters Functions */

     /**
      * @dev Deposit CRKS tokens to the contract.
      * @param amount The amount of CRKS tokens to deposit.
      */
     function depositCrooks(uint256 amount) external onlyOwner {
          // Checks
          if(amount == 0) {revert CrksStak__InvalidAmount();}
          if(amount > _crks.balanceOf(msg.sender)) {revert CrksStak__NotEnoughBalance();}
          // Allowance check (Need to approve the contract to spend the amount first)
          if(amount > _crks.allowance(msg.sender, address(this))) {revert CrksStak__NotEnoughAllowance();}
          // Transfer CRKS from owner to contract
          if(!_crks.transferFrom(msg.sender, address(this), amount)) {revert CrksStak__TransferFailed();}
          // Update the balance for rewards
          crksBalanceForRewards += amount;
     }

     /**
      * @dev Set Staking Logic Contract Address.
      * @param stakingLogicsAddress The address of the Staking Logics Contract.
      */
     function setStakingLogicsAddress(address stakingLogicsAddress) external onlyOwner {
          _stakingLogics = StakingLogics(stakingLogicsAddress);
     }

     /**
      * @dev Set the staking rules.
      * @param minStakingPeriod The minimum staking period in months.
      * @param maxStakingPeriod The maximum staking period in months.
      * @param aprXmonthly The APR per month in decimal percentage (e.g. 500 for 0.5%).
      */
     function setStakingRules(uint256 maxAmount, uint8 minStakingPeriod, uint16 maxStakingPeriod, uint24 aprXmonthly) external onlyOwner {
          infoIndex++;
          StakingRules storage info = _stakingRule[infoIndex];
          info.maxAmount = maxAmount;
          info.minStakingPeriod = minStakingPeriod; // in months
          info.maxStakingPeriod = maxStakingPeriod; // "" ""
          info.APRxMonths = aprXmonthly; // in decimal percentage (e.g. 500 for 0.5%)
          info.lastChange = uint32(block.timestamp);
     }

     /**
      * @dev Set the rank parameters.
      * @param rankName The name of the rank.
      * @param minStakedAmount The minimum staked amount to achieve this rank.
      * @param minLegendsAmount The minimum amount of legends to achieve this rank.
      * @param aprBonus The APR bonus for this rank.
      * @param rankDistribution The rank distribution percentage.
      */
     function setRank(string memory rankName, uint256 minStakedAmount, uint16 minLegendsAmount, uint24 aprBonus, uint8 rankDistribution) external onlyOwner {
          _rank[rankName] = Rank(minStakedAmount, minLegendsAmount, aprBonus, rankDistribution);
     }

     /**
      * @dev Set the Ultimate Crook address.
      * @param account The address of the Ultimate Crook.
      */
     function setUC_address(address account) external onlyOwner {
          UserUltimate storage ultimate = _userUltimate[account];
          // Set the Ultimate Crook
          _ultimateBonus.ultimateCrook = account;
          // Add the Ultimate Crook
          ultimate.uC = true;
          ultimate.fromTimestamp = uint32(block.timestamp);
          ultimate.toTimestamp = uint32(ultimate.fromTimestamp + _ONE_MONTH);
     }

     /**
      * @dev Set the APR for the Ultimate Crook.
      * @param aprUC The APR percentage for the Ultimate Crook.
      */
     function setUC_apr(uint8 aprUC) external onlyOwner {
          _ultimateBonus.aprUC = aprUC;
     } 

     /**
      * @dev Add a partnership token.
      * @param tokenAddress The address of the partnership token.
      */
     function addPartnership(address tokenAddress) external onlyOwner {
          // Check if the token is already in the array
          for(uint i = 0; i < _partnerships.length; i++) {
               if(_partnerships[i] == tokenAddress) {revert CrksStak__PartnershipExists();}
          }
          // Check if the token is a valid ERC20
          IERC20 token = IERC20(tokenAddress);
          if(token.totalSupply() == 0) {revert CrksStak__InvalidERC20token();}
          // Add the token to the array
          _partnerships.push(tokenAddress);
     }

     /**
      * @dev Remove a partnership token and cancel users' pending rewards for that token.
      * @param tokenAddress The address of the token to remove.
      */
     function removePartnership(address tokenAddress) external onlyOwner {
          // Check if the token is in the array
          for(uint i = 0; i < _partnerships.length; i++) {
               if(_partnerships[i] == tokenAddress) {
                    // Remove the token from the array
                    _partnerships[i] = address(0);
                    return;
               }
          }
          // If the token is not in the array
          revert CrksStak__PartnershipNotExists();
     }

     /**
      * @dev Set the alignment bonus parameters.
      * @param crksReq The required amount of CRKS tokens.
      * @param crklReq The required amount of CRKL tokens.
      * @param aprBonus The APR bonus for alignment.
      */
     function setAlignBonus(uint256 crksReq, uint16 crklReq, uint24 aprBonus) external onlyOwner {
          _alignBonus = AlignBonus(crksReq, crklReq, aprBonus); // 3 Decimals
     }

     /**
      * @dev Set the contract balance percentages for rank rewards.
      * @param croPerc The percentage for CRO rewards.
      * @param nutsPerc The percentage for NUTS rewards.
      * @param pttPerc The percentage for partnership token rewards.
      */
     function setContractBalancePercForRankRew(uint8 croPerc, uint8 nutsPerc, uint8 pttPerc) external onlyOwner {
          if(croPerc > 100 || nutsPerc > 100 || pttPerc > 100) {revert CrksStak__InvalidAmount();}
          contractBalancePercForRankRew = [croPerc, nutsPerc, pttPerc];
     }

     /**
      * @dev Save the daily rank rewards information.
      */
     function saveRankRewardsDailyInfos() external onlyOwner {
          // Set up
          uint32 timestamp = uint32(block.timestamp);
          uint256 croBalance = address(this).balance;
          uint256 nutsBalance = _nuts.balanceOf(address(this));
          uint256[] memory pttBalance;
          // Calculate the daily rewards (overwrite existing vars just to save gas)
          croBalance = croBalance * contractBalancePercForRankRew[0] / 100; // 5% of the contract balance
          nutsBalance = nutsBalance * contractBalancePercForRankRew[1] / 100; // "" ""
          if(_partnerships.length > 0) {
               // Save the balances of the _partnerships tokens
               pttBalance = new uint256[](_partnerships.length);
               for(uint i = 0; i < _partnerships.length; i++) {
                    if(_partnerships[i] != address(0)) {
                         IERC20 partner = IERC20(_partnerships[i]);
                         pttBalance[i] = partner.balanceOf(address(this));
                         pttBalance[i] = pttBalance[i] * contractBalancePercForRankRew[2] / 100; // "" ""
                    }
               }
          }
          // Save the daily rewards
          _rankRewardsDailyDistr.push(RankRewardsDailyDistr(timestamp, croBalance, nutsBalance, pttBalance, _rankCounters["MEMBER"], _rankCounters["HUSTLER"], _rankCounters["STREET SOLDIER"], _rankCounters["ENFORCER"], _rankCounters["OFFICER"], _rankCounters["CAPTAIN"], _rankCounters["GENERAL"], _rankCounters["GANG LEADER"], _rankCounters["BOSS"]));
     }

     /**
      * @dev Withdraw ETH from the contract.
      * @param amount The amount of ETH to withdraw.
      */
     function withdrawETH(uint256 amount) external onlyOwner {
          // Checks
          if(amount == 0) {revert CrksStak__InvalidAmount();}
          if(amount > address(this).balance) {revert CrksStak__NotEnoughContractBalance();}
          // Transfer ETH to owner
          (bool success, ) = msg.sender.call{value: amount}("");
          if(!success) {revert CrksStak__TransferFailed();}
     }

     /**
      * @dev Withdraw ERC20 tokens from the contract.
      * @param tokenAddress The address of the ERC20 token.
      * @param amount The amount of tokens to withdraw.
      */
     function withdrawERC20(address tokenAddress, uint256 amount) external onlyOwner {
          // Checks
          if(amount == 0) {revert CrksStak__InvalidAmount();}
          IERC20 token = IERC20(tokenAddress);
          if(amount > token.balanceOf(address(this))) {revert CrksStak__NotEnoughContractBalance();}
          // Transfer ERC20 to owner
          if(!token.transfer(msg.sender, amount)) {revert CrksStak__TransferFailed();}
     }

     /* Internal Functions */

     /**
      * @dev Authorize the upgrade of the contract.
      * @param newImplementation The address of the new implementation.
      */
    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
        // This block is intentionally left empty
    }

     /* External & Public View & Pure Functions */

     /**
      * @dev Handle the receipt of an ERC721 token.
      * @return The selector of the function.
      */
    function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
        return this.onERC721Received.selector;
    }

     /**
      * @dev Get the address of the Ultimate Crook.
      * @return The address of the Ultimate Crook.
      */
     function ultimateAddress() external view returns (address) {
          return (_ultimateBonus.ultimateCrook);
     }

     /**
      * @dev Get the alignment bonus information.
      * @return crksReq The required amount of CRKS tokens.
      * @return crklReq The required amount of CRKL tokens.
      * @return aprBonus The APR bonus for alignment.
      */
     function getAlignBonusInfo() external view returns (uint256 crksReq, uint16 crklReq, uint24 aprBonus) {
          return (_alignBonus.crksReq, _alignBonus.crklReq, _alignBonus.aprBonus);
     }

     /**
      * @dev Get the CRKS stake information for an account.
      * @param account The address of the account.
      * @return CrksStake The CRKS stake information.
      */
     function getCrksStake(address account) external view returns (CrksStake memory) {
          return _crksStakes[account];
     }

     /**
      * @dev Get the CRKS claims information for an account.
      * @param account The address of the account.
      * @return CrksClaim The CRKS claims information.
      */
     function getCrksClaims(address account) external view returns (CrksClaim memory) {
          return _crksClaims[account];
     }

     /**
      * @dev Get the current staking rules.
      * @param _infoIndex The index of the staking information.
      * @return The staking rules.
      */
     function getStakingRule(uint32 _infoIndex) external view returns (StakingRules memory) {
          return _stakingRule[_infoIndex];
     }

     /**
      * @dev Get the rank information.
      * @param rankName The name of the rank.
      * @return minStakedAmount The minimum staked amount to achieve this rank.
      * @return minLegendsAmount The minimum amount of legends to achieve this rank.
      * @return aprBonus The APR bonus for this rank.
      * @return rankDistribution The rank distribution percentage.
      */
     function getRankInfo(string memory rankName) external view returns (uint256 minStakedAmount, uint16 minLegendsAmount, uint24 aprBonus, uint8 rankDistribution) {
          Rank memory rankInfo = _rank[rankName];
          return (rankInfo.minStakedAmount, rankInfo.minLegendsAmount, rankInfo.aprBonus, rankInfo.rankDistribution);
     }

     /**
      * @dev Get the actual alignment bonus APR for a user.
      * @param account The address of the user.
      * @return apr The APR bonus for the alignment.
      */
     function getActualUserAlignBonus(address account) external view returns (uint256 apr) {   // Returns APR bonus for the alignment (3 Decimals - 0.100%) 
          uint256 crksStaked = _crksStakes[account].amount;
          NftStake memory nftStake = getLastNftStake(account);
          uint16 stakedCRKL = nftStake.amount;

          return _stakingLogics.calcAlignBonusApr(crksStaked, stakedCRKL);
     }

     /**
      * @dev Get the APR percentage for the Ultimate Crook.
      * @return aprUC The APR percentage for the Ultimate Crook.
      */
     function getUC_perc() external view returns (uint8 aprUC) {
          return (_ultimateBonus.aprUC);
     }

     /**
      * @dev Get the Ultimate Crook information for a user.
      * @param account The address of the user.
      * @return uC The Ultimate Crook status.
      */
     function getUltimateUser(address account) external view returns (UserUltimate memory) {
          return _userUltimate[account];
     }

     /**
      * @dev Get the rank rewards claim information for a user.
      * @param account The address of the user.
      * @return The rank rewards claim information.
      */
     function getRankRewardsClaim(address account) external view returns (RankRewardsClaim memory) {
          return _rankRewClaim[account];
     }

     /**
      * @dev Get the daily rank rewards distribution information.
      * @return The array of daily rank rewards distribution information.
      */
     function getRankRewDailyDistr() external view returns (RankRewardsDailyDistr[] memory) {
          return _rankRewardsDailyDistr;
     }

     /**
      * @dev Get the last daily rank rewards distribution information.
      * @return The last daily rank rewards distribution information.
      */
     function getLastRankRewDailyDistr() external view returns (uint32, uint256, uint256, uint256[] memory, uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16) {
          RankRewardsDailyDistr memory distr = _rankRewardsDailyDistr[_rankRewardsDailyDistr.length - 1];
          return (distr.timestamp, distr.croRewards, distr.nutsRewards, distr.pttRewards, distr.nOfMembers, distr.nOfHustlers, distr.nOfStreetSoldiers, distr.nOfEnforcers, distr.nOfOfficers, distr.nOfCaptains, distr.nOfGenerals, distr.nOfGangLeaders, distr.nOfBosses);

     }

     function getNftStakes(address account) external view returns (NftStake[] memory) {
          return _nftStakes[account];
     }

     function getPartnerships() external view returns (address[] memory) {
          return _partnerships;
     }

     /* Public View Functions */

     /**
      * @dev Get the last NFT stake information for a user.
      * @param account The address of the user.
      * @return The last NFT stake information.
      */
     function getLastNftStake(address account) public view returns (NftStake memory) {
          if (_nftStakes[account].length == 0) {
               return NftStake(0, new uint16[](0), 0);
          }
          uint256 length = _nftStakes[account].length;
          return _nftStakes[account][length - 1];
     }

     function getCounter(string memory rankName) external view returns (uint16) {
          return _rankCounters[rankName];
     }
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

File 3 of 33 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }

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

File 4 of 33 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

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

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

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

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

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

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

File 5 of 33 : IERC721ReceiverUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721ReceiverUpgradeable {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

File 7 of 33 : CRKS.sol
/**                                                                                        
                                                                                                                      
 ________  ________  ________  ________  ___  __    ________      
|\   ____\|\   __  \|\   __  \|\   __  \|\  \|\  \ |\   ____\     
\ \  \___|\ \  \|\  \ \  \|\  \ \  \|\  \ \  \/  /|\ \  \___|_    
 \ \  \    \ \   _  _\ \  \\\  \ \  \\\  \ \   ___  \ \_____  \   
  \ \  \____\ \  \\  \\ \  \\\  \ \  \\\  \ \  \\ \  \|____|\  \  
   \ \_______\ \__\\ _\\ \_______\ \_______\ \__\\ \__\____\_\  \ 
    \|_______|\|__|\|__|\|_______|\|_______|\|__| \|__|\_________\
                                                      \|_________|
                                                                                                                                                                    
      
      Crooks(TM) 
      Website: https://crooks.finance/
      Telegram: https://t.me/crookstoken
      X: https://x.com/crooksfinance


 * @title $CRKS Token
 * @author ETHERCODE - Exit : https://www.ethercode.dev/
 * @notice This contract represents the $CRKS (v2) token for the Crooks Finance project.

 */

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {SafeERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import {ERC20SnapshotUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol";
import {ERC20PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IUniswapV2Router02} from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import {IUniswapV2Factory} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import {IUniswapV2Pair} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";

contract Crooks is Initializable, UUPSUpgradeable, OwnableUpgradeable, ERC20Upgradeable, ERC20PausableUpgradeable, ERC20SnapshotUpgradeable {

    using SafeERC20Upgradeable for ERC20Upgradeable;

    error Crks__InvalidAmount();
    error Crks__ZeroAddress();
    error Crks__ContractPaused();
    error Crks__ContractNotPaused();
    error Crks__TransferFailed(address addr);
    error Crks__BlacklistedAddress(address addr);
    error Crks__AlreadyBlacklisted(address addr);
    error Crks__NotBlacklisted(address addr);
    error Crks__AlreadyExcluded(address addr);
    error Crks__NotExcluded(address addr);
    error Crks__TaxExceedsLimit(uint256 tax);

    uint16 private constant _DENOMINATOR = 1000;
    uint256 constant _APR_DENOMINATOR = 1000; // 3 Decimals
    address constant _USDC = 0xc21223249CA28397B4B6541dfFaEcC539BfF0c59;
    address constant _WCRO = 0x5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23;

    uint8 private _buyTax;
    uint8 private _sellTax;

    address private _stakedCapitalWallet;

    IUniswapV2Pair private _uniswapV2Pair;
    IUniswapV2Factory private _uniswapV2Factory;
    IUniswapV2Router02 private _uniswapV2Router02;

    mapping (address => bool) private _blacklist;
    mapping (address => bool) private _excludeList;

    event TaxHandled(uint256 amount, uint256 tax);

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize() public initializer {
        __Ownable_init();
        __ERC20_init("Crooks", "CRKS");
        __ERC20Pausable_init();
        __ERC20Snapshot_init();
        __UUPSUpgradeable_init();
        _buyTax = 50; // 5%
        _sellTax = 50; // 5%
        _excludeList[address(this)] = true;
        _excludeList[msg.sender] = true;
        _mint(msg.sender, 100000000 ether);
    }

    receive() external payable {}

    /* Setter Functions */ 

    function createSnapshot() external onlyOwner {
        _snapshot();
    }

    function pause() external onlyOwner {
        if(paused()) revert Crks__ContractPaused();
        _pause();
    }

    function unpause() external onlyOwner {
        if(!paused()) revert Crks__ContractNotPaused();
        _unpause();
    }

    function enableBlacklist(address account) external onlyOwner {
        if(_blacklist[account]) revert Crks__AlreadyBlacklisted(account);
        _blacklist[account] = true;
    }

    function disableBlacklist(address account) external onlyOwner {
        if(!_blacklist[account]) revert Crks__NotBlacklisted(account);
        _blacklist[account] = false;
    }

    function setBuyTax(uint8 tax) external onlyOwner {
        if(tax > 50) revert Crks__TaxExceedsLimit(tax); // 5%
        _buyTax= tax;
    }

     function setSellTax(uint8 tax) external onlyOwner {
        if(tax > 50) revert Crks__TaxExceedsLimit(tax); // 5%
        _sellTax = tax;
    }

    function setStakedCapitalWallet(address account) external onlyOwner {
        if(account == address(0)) revert Crks__ZeroAddress();
        _stakedCapitalWallet = account;
        if(!isExcluded(account)) exclude(_stakedCapitalWallet);
    }

    function setRouterAddress(address account) external onlyOwner{
        if(account == address(0)) revert Crks__ZeroAddress();

        _uniswapV2Router02 = IUniswapV2Router02(account);
        _uniswapV2Factory = IUniswapV2Factory(_uniswapV2Router02.factory());

        address pairAddress = IUniswapV2Factory(_uniswapV2Router02.factory()).getPair(address(this), _uniswapV2Router02.WETH());
        if(pairAddress == address(0)) pairAddress = _uniswapV2Factory.createPair(address(this), _uniswapV2Router02.WETH());
        _uniswapV2Pair = IUniswapV2Pair(pairAddress);
    }

    function withdrawETH() external onlyOwner {
        (bool success, ) = msg.sender.call{value: address(this).balance}("");
        if(!success) revert Crks__TransferFailed(msg.sender);
    }

    function withdrawTokens(address tokenAddress) external onlyOwner {
        uint256 balance = IERC20(tokenAddress).balanceOf(address(this));
        IERC20(tokenAddress).transfer(msg.sender, balance);
    }

    function exclude(address account) public onlyOwner {
        if(isExcluded(account)) revert Crks__AlreadyExcluded(account);
        _excludeList[account] = true;
    }

    function removeExclude(address account) public onlyOwner {
        if(!isExcluded(account)) revert Crks__NotExcluded(account);
        _excludeList[account] = false;
    }
    
    /* Getter Functions */
    
    function isBlacklisted(address account) public view returns (bool) {
        return _blacklist[account];
    }

    function isExcluded(address account) public view returns (bool) {
        return _excludeList[account];
    }

    function currentSnapshotId() external view returns (uint256) {
        return super._getCurrentSnapshotId();
    }

    function getStakedCapitalWallet() external view returns (address) {
        return _stakedCapitalWallet;
    }

    function getRouterAddress() external view returns (address) {
        return address(_uniswapV2Router02);
    }

    function getPairAddress() external view returns (address) {
        return address(_uniswapV2Pair);
    }

    function getBuyTax() external view returns (uint8) {
        return _buyTax;
    }

    function getSellTax() external view returns (uint8) {
        return _sellTax;
    }

    // Logic for uncap APR on CrooksStakingV2
     function getCrksAmountToUncapApr(uint256 aprPerc, uint8 uncapOnePercAPRinUSDT) external view returns (uint256) {
          // Calculate the amount of USDT to uncap the APR
          uint256 amount = uncapOnePercAPRinUSDT * aprPerc / _APR_DENOMINATOR;
          // Multiply by the decimals (6)
          amount = amount * 10**6;
          // Set the Path
          address[] memory path = new address[](3);
          path[0] = address(_USDC);
          path[1] = address(_WCRO);
          path[2] = address(this);
          // Get the Amounts out converting to WCRO and then to CRKS
          amount = _uniswapV2Router02.getAmountsOut(amount, path)[2];
          // Return the amount
          return amount;
     }

    /* Internal Functions */

    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
        // This block is intentionally left empty
    }

    function _transfer(
        address sender,
        address recipient,  
        uint256 amount
    ) internal override virtual whenNotPaused {
        if(isBlacklisted(msg.sender)) revert Crks__BlacklistedAddress(msg.sender);
        if(isBlacklisted(sender)) revert Crks__BlacklistedAddress(sender);
        if(isBlacklisted(recipient)) revert Crks__BlacklistedAddress(recipient);
        bool isSwap = sender == address(_uniswapV2Pair) || recipient == address(_uniswapV2Pair);

        // Handle tax
        if (!isExcluded(sender) && !isExcluded(recipient) && isSwap && _uniswapV2Router02 != IUniswapV2Router02(address(0)) && _stakedCapitalWallet != address(0)) {
            uint256 tax = calculateTax(amount, sender == address(_uniswapV2Pair));
            if(tax > 0) {
                _handleTax(sender, amount);
                amount = amount - tax;
            }
        }

        super._transfer(sender, recipient, amount);
        
    }   


    function calculateTax(uint256 amount, bool isBuy) private view returns (uint256) {
        uint256 tax;
        uint256 baseUnit = amount / _DENOMINATOR;

        if(isBuy) {
            tax = baseUnit * _buyTax;    // if is a buy
        }
        else {
            tax = baseUnit * _sellTax;   // if is a sell
        }

        return tax;
    }

    function _handleTax(address from, uint256 amount) private {

        uint256 tax = calculateTax(amount, from == address(_uniswapV2Pair));
        // Set router var
        IUniswapV2Router02 router = _uniswapV2Router02;
        // Approve tax
        _approve(from, address(this), tax);
        // Transfer tax to this contract
        super._transfer(from, address(this), tax);
        // Approve tax
        _approve(address(this), address(router), tax);
        // Save initial balance
        uint256 startBalance = address(this).balance;

        // Swap tax for ETH
        address[] memory sellPath = new address[](2);
        sellPath[0] = address(this);
        sellPath[1] = router.WETH();

        router.swapExactTokensForETH(
            tax,
            0,
            sellPath,
            address(this),
            block.timestamp
        );

        // Calculate staked capital ETH
        uint256 stakedCapETH = address(this).balance - startBalance;

        // Transfer tax to staked capital wallet
        (bool success, ) = _stakedCapitalWallet.call{value: stakedCapETH}("");
        if(!success) revert Crks__TransferFailed(_stakedCapitalWallet);

        // Emit event
        emit TaxHandled(amount, tax);
    }

    function _beforeTokenTransfer(address from, address to, uint256 amount)
        internal
        whenNotPaused
        override(ERC20Upgradeable, ERC20SnapshotUpgradeable, ERC20PausableUpgradeable)
    {
        super._beforeTokenTransfer(from, to, amount);
    }

}

File 8 of 33 : NUTS.sol
/**                                                                                  

            ██                             
              ██                          
        ██████████████  
      ██████████████████ 
    ████▓▓▓▓██████████▓▓▓▓         
    ██████████████████████   
    ██░░░░░░░░░░░░░░░░░░██        
      ░░▒▒░░░░░░▒▒░░░░░░            
      ░░▒▒░░░░▒▒░░▒▒░░░░                                  
      ░░▒▒▒▒░░░░░░░░░░░░           
      ░░░░░░░░░░░░▒▒░░░░                                  
        ░░░░░░░░▒▒░░░░       
         ░░░░░░░░░░░░ 
            ░░▒▒░░
                                            

    888b    | 888   | ~~~888~~~ ,d88~~\ 
    |Y88b   | 888   |    888    8888    
    | Y88b  | 888   |    888    `Y88b   
    |  Y88b | 888   |    888     `Y88b, 
    |   Y88b| Y88   |    888       8888 
    |    Y888  "8__/     888    \__88P' 
                                        

      Crooks(TM) 
      Website: https://crooks.finance/
      Telegram: https://t.me/crookstoken
      X: https://x.com/crooksfinance


 * @title $NUTS Token
 * @author ETHERCODE - Exit : https://www.ethercode.dev/
 * @notice $NUTS Token is the game currency of Crooks Empire.

 */

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {SafeERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import {ERC20SnapshotUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol";
import {ERC20PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract Nuts is Initializable, UUPSUpgradeable, OwnableUpgradeable, ERC20Upgradeable, ERC20PausableUpgradeable, ERC20SnapshotUpgradeable {

    using SafeERC20Upgradeable for ERC20Upgradeable;

    error Nuts__InvalidAmount();
    error Nuts__ZeroAddress();
    error Nuts__ContractPaused();
    error Nuts__ContractNotPaused();
    error Nuts__TransferFailed(address addr);
    error Nuts__BlacklistedAddress(address addr);
    error Nuts__AlreadyBlacklisted(address addr);
    error Nuts__NotBlacklisted(address addr);
    error Nuts__NotController(address addr);

    mapping (address => bool) private _blacklist;
    mapping (address => bool) private _controllers;

    event ControllerAdded(address indexed account);
    event ControllerRemoved(address indexed account);

    modifier onlyControllers() {
        if(!_controllers[msg.sender]) revert Nuts__NotController(msg.sender);
        _;
    }

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize() public initializer {
        __Ownable_init();
        __ERC20_init("Nuts", "NUTS");
        __ERC20Pausable_init();
        __ERC20Snapshot_init();
        __UUPSUpgradeable_init();
        _controllers[msg.sender] = true;
    }

    receive() external payable {}

    /* Setter Functions */ 

    function mint(address account, uint256 amount) external onlyControllers {
        if(account == address(0)) revert Nuts__ZeroAddress();
        if(amount == 0) revert Nuts__InvalidAmount();
        _mint(account, amount);
    }

    function createSnapshot() external onlyOwner {
        _snapshot();
    }

    function pause() external onlyOwner {
        if(paused()) revert Nuts__ContractPaused();
        _pause();
    }

    function unpause() external onlyOwner {
        if(!paused()) revert Nuts__ContractNotPaused();
        _unpause();
    }

    function enableBlacklist(address account) external onlyOwner {
        if(_blacklist[account]) revert Nuts__AlreadyBlacklisted(account);
        _blacklist[account] = true;
    }

    function disableBlacklist(address account) external onlyOwner {
        if(!_blacklist[account]) revert Nuts__NotBlacklisted(account);
        _blacklist[account] = false;
    }

    function addController(address account) external onlyOwner {
        _controllers[account] = true;
        emit ControllerAdded(account);
    }

    function removeController(address account) external onlyOwner {
        _controllers[account] = false;
        emit ControllerRemoved(account);
    }

    function withdrawETH() external onlyOwner {
        (bool success, ) = msg.sender.call{value: address(this).balance}("");
        if(!success) revert Nuts__TransferFailed(msg.sender);
    }

    function withdrawTokens(address tokenAddress) external onlyOwner {
        uint256 balance = IERC20(tokenAddress).balanceOf(address(this));
        IERC20(tokenAddress).transfer(msg.sender, balance);
    }

    
    /* Getter Functions */
    
    function isBlacklisted(address account) public view returns (bool) {
        return _blacklist[account];
    }

    function currentSnapshotId() external view returns (uint256) {
        return super._getCurrentSnapshotId();
    }

    function isController(address account) external view returns (bool) {
        return _controllers[account];
    }


    /* Internal Functions */

    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
        // This block is intentionally left empty
    }

    function _transfer(
        address sender,
        address recipient,  
        uint256 amount
    ) internal override virtual whenNotPaused {
        if(isBlacklisted(msg.sender)) revert Nuts__BlacklistedAddress(msg.sender);
        if(isBlacklisted(sender)) revert Nuts__BlacklistedAddress(sender);
        if(isBlacklisted(recipient)) revert Nuts__BlacklistedAddress(recipient);

        // Transfer amount
        super._transfer(sender, recipient, amount);
    }   

    function _beforeTokenTransfer(address from, address to, uint256 amount)
        internal
        whenNotPaused
        override(ERC20Upgradeable, ERC20SnapshotUpgradeable, ERC20PausableUpgradeable)
    {
        super._beforeTokenTransfer(from, to, amount);
    }

}

File 9 of 33 : ICrooksLegends.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

interface ICrooksLegends {
    function balanceOf(address owner) external view returns (uint256);
    function tokensOfOwnerIn(address owner, uint256 start, uint256 stop) external view returns (uint256[] memory);
    function ownerOf(uint256 tokenId) external view returns (address);
    function isApprovedForAll(address owner, address operator) external view returns (bool);
    function safeTransferFrom(address from, address to, uint256 tokenId) external;
}

File 10 of 33 : StakingLogics.sol
/**                                                                                        
                                                                                                                      
 ________  ________  ________  ________  ___  __    ________      
|\   ____\|\   __  \|\   __  \|\   __  \|\  \|\  \ |\   ____\     
\ \  \___|\ \  \|\  \ \  \|\  \ \  \|\  \ \  \/  /|\ \  \___|_    
 \ \  \    \ \   _  _\ \  \\\  \ \  \\\  \ \   ___  \ \_____  \   
  \ \  \____\ \  \\  \\ \  \\\  \ \  \\\  \ \  \\ \  \|____|\  \  
   \ \_______\ \__\\ _\\ \_______\ \_______\ \__\\ \__\____\_\  \ 
    \|_______|\|__|\|__|\|_______|\|_______|\|__| \|__|\_________\
                                                      \|_________|
                                                                                                                                                                    
      
      Crooks(TM) 
      Website: https://crooks.finance/
      Telegram: https://t.me/crookstoken
      X: https://x.com/crooksfinance


 * @title Crooks Staking Logics
 * @author ETHERCODE - Exit : https://www.ethercode.dev/ 
 * @notice This contract contains some logics for the Crooks Staking V2 contract.

 */

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {CrooksStakingV2} from "./CrooksStakingV2.sol";
import {IScoreArray} from "./interfaces/IScoreArray.sol";

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract StakingLogics is Initializable, OwnableUpgradeable, UUPSUpgradeable {

     /* Custom Errors */
     error CrksLogic__AddressZero();
     error CrksLogic__DifferentArrayLength();
     error CrksLogic__PartnershipsNotExist();
     error CrksLogic__OverflowInput();

     /* Structs */
     struct RankRewardsDailyDistr {
          uint32 timestamp; // Last variables saving timestamp
          uint256 croRewards; // Rewards to distribute Daily
          uint256 nutsRewards; // "" "" 
          uint256[] pttRewards; // "" ""
          uint16 nOfMembers; // Number of members that day
          uint16 nOfHustlers;
          uint16 nOfStreetSoldiers;
          uint16 nOfEnforcers;
          uint16 nOfOfficers;
          uint16 nOfCaptains;
          uint16 nOfGenerals;
          uint16 nOfGangLeaders;
          uint16 nOfBosses;
     }

     /* State Variables */

     uint256 private constant _ONE_MONTH = 2629743; // in seconds
     uint256 private constant _ONE_YEAR = 31556916; // 12 months in seconds
     uint256 private constant _APR_DENOMINATOR = 1000; // 3 Decimals
     uint256 private constant _NFT_QUALITY_DENOMINATOR = 100000000000000000000;

     CrooksStakingV2 public staking;
     IScoreArray public scoreArray;
     string[] private _partnershipsImages;

     uint256 public availableCroBalance;
     uint256 public availableNutsBalance;
     uint256[] public availablePttBalance;

     uint8[] public contractBalancePercForRankRew;

     RankRewardsDailyDistr[] private _rankRewardsDailyDistr;

     /**
      * @dev Constructor to disable initializers.
      */
     constructor() {
          _disableInitializers();
     }

     /**
      * @dev Initialize the contract with staking and score array addresses.
      * @param stakingV2Address The address of the staking contract.
      * @param scoreArrayAddress The address of the score array contract.
      */
     function initialize(address stakingV2Address, address scoreArrayAddress) initializer public {
          __Ownable_init();
          __UUPSUpgradeable_init();

          staking = CrooksStakingV2(payable(stakingV2Address));
          scoreArray = IScoreArray(scoreArrayAddress);

          contractBalancePercForRankRew = [5, 5, 5]; // 5% of the contract balance for CRO, NUTS and PTT
     }

     /**
      * @dev Calculate the alignment bonus APR.
      * @param crksStaked The amount of CRKS staked.
      * @param crklStaked The amount of CRKL staked.
      * @return apr The alignment bonus APR.
      */
     function calcAlignBonusApr(uint256 crksStaked, uint16 crklStaked) public view returns (uint256 apr) {   // Returns APR bonus for the alignment (3 Decimals - 0.100%) 
          // Set up
          uint256 crksReq;
          uint16 crklReq;
          uint24 aprBonus;
          (crksReq, crklReq, aprBonus) = staking.getAlignBonusInfo();
          uint16 alignLegends;
          uint256 alignCrooks;
          uint256 alignCoeff;

          if(crklStaked < crklReq || crksStaked < crksReq){
               return 0;
          } 
          else{
               alignLegends = crklStaked / crklReq;
               alignCrooks = crksStaked / crksReq;
          }

          if(alignLegends <= alignCrooks){
               alignCoeff = alignLegends;
          } else {alignCoeff = alignCrooks;}

          return aprBonus * alignCoeff;
     }

     /**
      * @dev Calculate the rank of a user.
      * @param stakedCRKS The amount of CRKS staked.
      * @param stakedCRKL The amount of CRKL staked.
      * @return The rank of the user.
      */
     function calcRank(uint256 stakedCRKS, uint16 stakedCRKL) public view returns (string memory) {
    // Define the ranks in order of priority
    string[10] memory ranks = ["BOSS", "GANG LEADER", "GENERAL", "CAPTAIN", "OFFICER", "ENFORCER", "STREET SOLDIER", "HUSTLER", "MEMBER", "PROSPECT"];
    
    // Iterate through the ranks and check the conditions
    for (uint256 i = 0; i < ranks.length; i++) {
        string memory rank = ranks[i];
        (uint256 minStakedAmount, uint16 minLegendsAmount, , ) = staking.getRankInfo(rank);
        if (stakedCRKS >= minStakedAmount && stakedCRKL >= minLegendsAmount) {
            return rank;
        }
    }
    
    // Default rank if no conditions are met
    return "PROSPECT";
}

     /**
      * @dev Get the accumulated APR for a user.
      * @param account The address of the user.
      * @return aprPerc The accumulated APR percentage.
      * @return zeroDecPerc The zero decimals bonus percentage.
      * @return nftQualBonus The NFT quality bonus.
      */
     function getUserAccumulatedApr(address account) public view returns (uint256 aprPerc, uint256 zeroDecPerc, uint256 nftQualBonus) { // Returns the accumulated APR for the user (NOT DIVIDED BY APR_DENOMINATOR)
          // Set up
          uint32 actualInfoIndex = staking.infoIndex();
          CrooksStakingV2.CrksStake memory stake = staking.getCrksStake(account);
          // Checks
          if(stake.amount == 0) {return (0, 0, 0);}
          // Set up
          CrooksStakingV2.CrksClaim memory claim = staking.getCrksClaims(account);
          uint256 period;
          uint32 lastTime;
          uint32 startIndex;
          uint256 totalApr = 0;
          uint256 zeroDecBonus = 0;
          uint256 nftBonus = 0;

          // Get the last time the user claimed or compounded (if any)
          if(claim.lastCompTime > 0 || claim.lastClaimTime > 0) {
               lastTime = claim.lastCompTime > claim.lastClaimTime ? claim.lastCompTime : claim.lastClaimTime;
               startIndex = claim.lastInfoIndex;
          } else {
               lastTime = stake.stakedAt;
               startIndex = stake.infoIndex;
          }

          // Check if last time is over Staking Period
          if(lastTime >= stake.stakedUntil) {
               return (0, 0, 0);
          }

          // Calculate the APR 
          uint32 lastCrksTime = lastTime; // So we don't lose the original last time (cuz the variable overwrites itself)
          for(uint32 i = startIndex; i <= actualInfoIndex; i++) {
               // Get Staking Rule
               CrooksStakingV2.StakingRules memory _stakingRule = staking.getStakingRule(i);
               // Get the APR of the info index
               uint24 apr = _stakingRule.APRxMonths * stake.stakedFor;
               // Calculate period with this APR
               if(i == actualInfoIndex) {
                    // Check if the staking period is over
                    if(uint32(block.timestamp) >= stake.stakedUntil) {
                         period = stake.stakedUntil - lastCrksTime;
                    } else {
                         period = uint32(block.timestamp) - lastCrksTime;
                    }
               } else {
                    // Get Staking Rule of the next index
                    CrooksStakingV2.StakingRules memory _nextStakingRule = staking.getStakingRule(i + 1);
                    // Check if the staking period is over
                    if(_nextStakingRule.lastChange >= stake.stakedUntil) {
                         period = stake.stakedUntil - lastCrksTime;
                         i = actualInfoIndex + 1; // Exit the loop
                    } else {
                         period = _nextStakingRule.lastChange - lastCrksTime;
                         lastCrksTime = _nextStakingRule.lastChange;
                    }                    
               }
               // Calculate the APR
               totalApr += apr * period / _ONE_YEAR;
          }

          // Calculate the NFT APR bonus
          uint32 lastNftTime = lastTime; // So we don't lose the original last time (cuz the variable overwrites itself)
          CrooksStakingV2.NftStake[] memory nftStakes = staking.getNftStakes(account);
          uint256 nftArrayLength = nftStakes.length; 
          if(nftArrayLength > 0) {                          // If the user has NFTs staking HISTORY
               // Calculate the period
               for(uint16 i = 0; i < nftArrayLength; i++) {
                    CrooksStakingV2.NftStake memory nft = nftStakes[i];

                    //  Check if lastNfttime is before the last NFT change
                    if (lastNftTime < nft.lastChange) {
                         lastNftTime = nft.lastChange;
                    }
                    
                    // Check if it's the last NFT
                    if(i == nftArrayLength - 1) {
                         // Check if the staking period is over
                         if(uint32(block.timestamp) >= stake.stakedUntil) {
                              period = stake.stakedUntil - lastNftTime;
                         }
                         else {
                              period = uint32(block.timestamp) - lastNftTime;
                         }
                    } 
                    else {
                         // Check if the staking period is over
                         if(nftStakes[i + 1].lastChange >= stake.stakedUntil) {
                              period = stake.stakedUntil - lastNftTime;
                              i = uint16(nftArrayLength); // Exit the loop
                         }
                         // Check if the last time is before the next NFT change
                         else if (nftStakes[i + 1].lastChange >= lastNftTime) {
                                period = nftStakes[i + 1].lastChange - lastNftTime;
                         }
                         else {
                              period = 0;
                         }
                    }
                    
                    if (period > 0) {
                         // Calculate the AlignBonus APR
                         totalApr += calcAlignBonusApr(stake.amount, nft.amount) * period / _ONE_YEAR;
                         // Calculate the RankBonus APR
                              // Get apr bonus for the rank
                         (, , uint24 aprBonus, ) = staking.getRankInfo(calcRank(stake.amount, nft.amount));
                         totalApr += aprBonus * period / _ONE_YEAR;
                         // Calculate the NftBonus APR
                         for(uint16 j = 0; j < nft.nftIds.length; j++) {
                              uint256 quality = scoreArray.return_score(nft.nftIds[j]);
                              nftBonus += quality * stake.stakedFor * period / _ONE_YEAR;  // Calculate APR per NFT
                         }
                    }
               }
          }

          // Calculate the UltimateBonus MPR (also 0 decimals)
          CrooksStakingV2.UserUltimate memory ultimate = staking.getUltimateUser(account);
          if(ultimate.uC && lastTime < stake.stakedUntil && lastTime < ultimate.toTimestamp && ultimate.fromTimestamp >= stake.stakedAt && ultimate.toTimestamp > stake.stakedAt) {
               if (lastTime < ultimate.fromTimestamp) {
                    lastTime = ultimate.fromTimestamp;
               }
               // Period calculation
               period = stake.stakedUntil > ultimate.toTimestamp ? ultimate.toTimestamp - lastTime : stake.stakedUntil - lastTime;
               // Calculate the UltimateBonus MPR
               zeroDecBonus = staking.getUC_perc() * period / _ONE_MONTH; // Monthly
          }

          // Return the total APR and the ZeroDecimals Bonus
          return (totalApr, zeroDecBonus, nftBonus);
     }

     /**
      * @dev Get the actual APR for a user.
      * @param account The address of the user.
      * @return aprPerc The APR percentage.
      * @return zeroDecPerc The zero decimals bonus percentage.
      * @return nftQualBonus The NFT quality bonus.
      */
     function getActualUserApr(address account) external view returns (uint256 aprPerc, uint256 zeroDecPerc, uint256 nftQualBonus) {
          // Set up
          uint32 actualInfoIndex = staking.infoIndex();
          CrooksStakingV2.CrksStake memory stake = staking.getCrksStake(account);
          // Checks
          if(stake.amount == 0) {return (0, 0, 0);}
          // Set up
          CrooksStakingV2.CrksClaim memory claim = staking.getCrksClaims(account);
          uint32 lastTime;
          uint256 totalApr = 0;
          uint256 zeroDecBonus = 0;
          uint256 nftBonus = 0;

          // Get the last time the user claimed or compounded (if any)
          if(claim.lastCompTime > 0 || claim.lastClaimTime > 0) {
               lastTime = claim.lastCompTime > claim.lastClaimTime ? claim.lastCompTime : claim.lastClaimTime;
          } else {
               lastTime = stake.stakedAt;
          }

          // Check if last time is over Staking Period
          if(lastTime >= stake.stakedUntil) {
               return (0, 0, 0);
          }

          // Calculate the APR 
               // Get Staking Rule
          CrooksStakingV2.StakingRules memory _stakingRule = staking.getStakingRule(actualInfoIndex);
          // Get the APR of the info index
          totalApr += _stakingRule.APRxMonths * stake.stakedFor;

          // Calculate the NFT APR bonus
          CrooksStakingV2.NftStake[] memory nftStakes = staking.getNftStakes(account);
          uint256 nftArrayLength = nftStakes.length; 
          if(nftArrayLength > 0) {                          // If the user has NFTs staking HISTORY
               CrooksStakingV2.NftStake memory nft = nftStakes[nftArrayLength - 1];
               // Calculate the AlignBonus APR
               totalApr += calcAlignBonusApr(stake.amount, nft.amount);
               // Calculate the RankBonus APR
                    // Get apr bonus for the rank
               (, , uint24 aprBonus, ) = staking.getRankInfo(calcRank(stake.amount, nft.amount));
               totalApr += aprBonus;
               // Calculate the NftBonus APR
               for(uint16 j = 0; j < nft.nftIds.length; j++) {
                    uint256 quality = scoreArray.return_score(nft.nftIds[j]);
                    nftBonus += quality * stake.stakedFor;  // Calculate APR per NFT
               }
          }

          // Calculate the UltimateBonus MPR (also 0 decimals)
          CrooksStakingV2.UserUltimate memory ultimate = staking.getUltimateUser(account);
          if(ultimate.uC && lastTime < stake.stakedUntil && lastTime < ultimate.toTimestamp && ultimate.fromTimestamp >= stake.stakedAt && ultimate.toTimestamp > stake.stakedAt) {
               // Calculate the UltimateBonus MPR
               zeroDecBonus = staking.getUC_perc();
          }

          // Return the total APR and the ZeroDecimals Bonus
          return (totalApr, zeroDecBonus, nftBonus);
     }

     /**
      * @dev Get the CRKS rewards for a user.
      * @param account The address of the user.
      * @return crksRewards The amount of CRKS rewards.
      */
     function getCrksRewards(address account) public view returns (uint256 crksRewards) {
          // Set up
          CrooksStakingV2.CrksStake memory stake = staking.getCrksStake(account);
          CrooksStakingV2.CrksClaim memory claim = staking.getCrksClaims(account);
          uint256 aprPerc;
          uint256 zeroDecPerc;
          uint256 nftQualBonus;
          uint256 rewards;
          uint256 totalApr;
          uint256 period;
          uint256 capPerc;
          // Checks
          if(stake.amount == 0) {return 0;}
          // Crks APR
          (aprPerc, zeroDecPerc, nftQualBonus) = getUserAccumulatedApr(account);
          if(aprPerc == 0) {return 0;}
          // Calculate the rewards
          rewards = stake.amount * aprPerc / 100 / _APR_DENOMINATOR;
          // Calculate the NFT Quality Bonus
          if (nftQualBonus > 0) {     
               nftQualBonus = nftQualBonus * stake.amount / 100 / _NFT_QUALITY_DENOMINATOR;
               rewards += nftQualBonus;
          }
          // Compare the rewards with the staked amount to get the total apr perc
          totalApr = rewards * 100000 / stake.amount; // --> 100000 = 100% * 1000 (decimals)

          // Calculate the period from staking / lastClaim to now / stakedUntil
          if(claim.lastCompTime > 0 || claim.lastClaimTime > 0) {
               period = claim.lastCompTime > claim.lastClaimTime ? claim.lastCompTime : claim.lastClaimTime;
          } else {
               period = stake.stakedAt;
          }
          if (block.timestamp >= stake.stakedUntil) {
               period = stake.stakedUntil - period;
          } else {
               period = uint32(block.timestamp) - period;
          }
          
          // What is the capped perc APR of that period ? Considering that 100% is the capped APR of 1 year
          capPerc = staking.cappedPercAPR() * period / _ONE_YEAR;

          // Check if the total APR is over the cap
          if(totalApr > capPerc) { 
               // // If the user has already an uncapped APR
               if (staking.userUncappedAPR(account) != 0) {
                    uint256 uncappedPerc = staking.userUncappedAPR(account) + staking.cappedPercAPR();
                    uncappedPerc = uncappedPerc * period / _ONE_YEAR;

                    // Check if the uncapped APR is more than the total APR
                    if (uncappedPerc >= totalApr) {
                         // Use the total APR
                         rewards = stake.amount * totalApr / 100 / _APR_DENOMINATOR;
                    } else {
                         // Use the saved uncapped APR */
                         rewards = stake.amount * uncappedPerc / 100 / _APR_DENOMINATOR;
                    }
               } else {
                    // Use the capped APR
                    rewards = stake.amount * capPerc / 100 / _APR_DENOMINATOR;
               }
          }
          // Calculate the ZeroDecimals Rewards --> NOT CAPPED
          if (zeroDecPerc > 0) {
               rewards += stake.amount * zeroDecPerc / 100;
          }
          // Return the rewards
          return rewards; 
     }

     /**
      * @dev Get the rank rewards for a user.
      * @param account The address of the user.
      * @return croRewards The amount of CRO rewards.
      * @return nutsRewards The amount of NUTS rewards.
      * @return pttRewards The amount of partnership token rewards.
      */
     function getRankRewards(address account) public view returns (uint256 croRewards, uint256 nutsRewards, uint256[] memory pttRewards) {
          // Set up
          CrooksStakingV2.CrksStake memory stake = staking.getCrksStake(account);
          address[] memory partnerships = staking.getPartnerships();
          uint256[] memory pttRew = new uint256[](partnerships.length);
          // Checks
          if(stake.amount == 0) {return (0, 0, pttRew);}
          // Setup
          CrooksStakingV2.RankRewardsClaim memory claim = staking.getRankRewardsClaim(account);
          string memory rank;
          uint32 startPeriod;
          uint32 endPeriod;
          uint32 lastTime;
          uint256 croRew;
          uint256 nutsRew;

          // Get the last time the user claimed or compounded (if any)
          if(claim.lastClaimTime > 0) {
               lastTime = claim.lastClaimTime;
          } else {
               lastTime = stake.stakedAt;
          }

          // Check if last time is over Staking Period
          if(lastTime >= stake.stakedUntil) {
               return (0, 0, pttRew);
          }

          // Calculate Period
          CrooksStakingV2.NftStake[] memory nftStakes = staking.getNftStakes(account);
          uint256 nftArrayLength =  nftStakes.length;
          if(nftArrayLength > 0) {                          // If the user has NFTs staking HISTORY
               // Calculate the period
               for(uint16 i = 0; i < nftArrayLength; i++) {
                    CrooksStakingV2.NftStake memory nft = nftStakes[i];

                    //  Check if lasttime is before the last NFT change
                    if (lastTime < nft.lastChange) {
                         lastTime = nft.lastChange;
                    }
                    
                    // Check if it's the last NFT
                    if(i == nftArrayLength - 1) {
                         // Check if the staking period is over
                         if(uint32(block.timestamp) >= stake.stakedUntil) {
                              startPeriod = lastTime;
                              endPeriod = uint32(stake.stakedUntil);
                         }
                         else {
                              startPeriod = lastTime;
                              endPeriod = uint32(block.timestamp);
                         }
                    } 
                    else {
                         // Check if the staking period is over
                         if(nftStakes[i + 1].lastChange >= stake.stakedUntil) {
                              startPeriod = lastTime;
                              endPeriod = uint32(stake.stakedUntil);
                              i = uint16(nftArrayLength); // Exit the loop
                         }
                         // Check if the last time is before the next NFT change
                         else if (nftStakes[i + 1].lastChange >= lastTime) {
                                startPeriod = lastTime;
                                endPeriod = nftStakes[i + 1].lastChange;
                         }
                         else {
                              startPeriod = 0;
                              endPeriod = 0;
                         }
                    }
                    
                    // Calculate the Rank Rewards
                    // Get the RankRewardsDailyDistr[]
                    if (startPeriod > 0 && endPeriod > 0 && _rankRewardsDailyDistr.length > 0) {
                         // Calc Rank 
                         rank = calcRank(stake.amount, nft.amount);
                         // For cycle of the saved RankRewardsDailyDistr[]
                         for (uint256 j = 0; j < _rankRewardsDailyDistr.length; j++) {
                              RankRewardsDailyDistr memory distr = _rankRewardsDailyDistr[j];
                              if (distr.timestamp > lastTime && distr.timestamp < stake.stakedUntil && distr.timestamp > startPeriod && distr.timestamp < endPeriod && keccak256(abi.encodePacked(rank)) != keccak256(abi.encodePacked("PROSPECT"))) {
                                   // Check the right rank counter
                                   uint256 rankCounter;
                                   if (keccak256(abi.encodePacked(rank)) == keccak256(abi.encodePacked("MEMBER"))) {
                                        rankCounter = distr.nOfMembers;
                                   } else if (keccak256(abi.encodePacked(rank)) == keccak256(abi.encodePacked("HUSTLER"))) {
                                        rankCounter = distr.nOfHustlers;
                                   } else if (keccak256(abi.encodePacked(rank)) == keccak256(abi.encodePacked("STREET SOLDIER"))) {
                                        rankCounter = distr.nOfStreetSoldiers;
                                   } else if (keccak256(abi.encodePacked(rank)) == keccak256(abi.encodePacked("ENFORCER"))) {
                                        rankCounter = distr.nOfEnforcers;
                                   } else if (keccak256(abi.encodePacked(rank)) == keccak256(abi.encodePacked("OFFICER"))) {
                                        rankCounter = distr.nOfOfficers;
                                   } else if (keccak256(abi.encodePacked(rank)) == keccak256(abi.encodePacked("CAPTAIN"))) {
                                        rankCounter = distr.nOfCaptains;
                                   } else if (keccak256(abi.encodePacked(rank)) == keccak256(abi.encodePacked("GENERAL"))) {
                                        rankCounter = distr.nOfGenerals;
                                   } else if (keccak256(abi.encodePacked(rank)) == keccak256(abi.encodePacked("GANG LEADER"))) {
                                        rankCounter = distr.nOfGangLeaders;
                                   } else if (keccak256(abi.encodePacked(rank)) == keccak256(abi.encodePacked("BOSS"))) {
                                        rankCounter = distr.nOfBosses;
                                   }
                                   (, , , uint8 rankDistribution) = staking.getRankInfo(rank);
                                   croRew += distr.croRewards * rankDistribution / 100 / rankCounter;
                                   nutsRew += distr.nutsRewards * rankDistribution / 100 / rankCounter;
                                   for(uint k = 0; k < distr.pttRewards.length; k++) {
                                        if(partnerships[k] != address(0)) {
                                             pttRew[k] += distr.pttRewards[k] * rankDistribution / 100 / rankCounter;
                                        }
                                   }
                              }
                         }
                    }
               }
          }

          // Return the rewards
          return (croRew, nutsRew, pttRew);
     }   

     /**
      * @dev Get the actual rank of a user.
      * @param account The address of the user.
      * @return The rank of the user.
      */
     function getActualUserRank(address account) external view returns (string memory) {  
          CrooksStakingV2.CrksStake memory stake = staking.getCrksStake(account);        
          uint256 stakedCRKS = stake.amount;
          uint16 stakedCRKL = 0;
          try staking.getLastNftStake(account) returns (CrooksStakingV2.NftStake memory nftStake) {
               stakedCRKL = nftStake.amount;
               return calcRank(stakedCRKS, stakedCRKL);
          } catch {
               return calcRank(stakedCRKS, 0);
          }
     }

     /**
      * @dev Get the partnerships images.
      * @return The array of partnership images.
      */
     function getPartnershipsImages() external view returns (string[] memory) {
          return _partnershipsImages;
     }

     /**
      * @dev Get the daily rank rewards distribution information.
      * @return The array of daily rank rewards distribution information.
      */
     function getRankRewDailyDistr() external view returns (RankRewardsDailyDistr[] memory) {
          return _rankRewardsDailyDistr;
     }

     /**
      * @dev Get the last daily rank rewards distribution information.
      * @return The last daily rank rewards distribution information.
      */
     function getLastRankRewDailyDistr() external view returns (uint32, uint256, uint256, uint256[] memory, uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16, uint16) {
          RankRewardsDailyDistr memory distr = _rankRewardsDailyDistr[_rankRewardsDailyDistr.length - 1];
          return (distr.timestamp, distr.croRewards, distr.nutsRewards, distr.pttRewards, distr.nOfMembers, distr.nOfHustlers, distr.nOfStreetSoldiers, distr.nOfEnforcers, distr.nOfOfficers, distr.nOfCaptains, distr.nOfGenerals, distr.nOfGangLeaders, distr.nOfBosses);

     }

     /**
      * @dev Set the staking contract.
      * @param stakingV2Address The address of the staking contract.
      */
     function setStaking(address stakingV2Address) external onlyOwner {
          if(stakingV2Address == address(0)){ revert CrksLogic__AddressZero(); }
          staking = CrooksStakingV2(payable(stakingV2Address));
     }

     /**
      * @dev Set the score array contract.
      * @param scoreArrayAddress The address of the score array contract.
      */
     function setScoreArray(address scoreArrayAddress) external onlyOwner {
          if(scoreArrayAddress == address(0)){ revert CrksLogic__AddressZero(); }
          scoreArray = IScoreArray(scoreArrayAddress);
     }

     /**
      * @dev Set the partnerships images.
      * @param tokenAddress The address of the partnership token.
      * @param image The images of the partnerships.
      */
      function setPartnershipImage(address tokenAddress, string memory image) external onlyOwner {
          if(tokenAddress == address(0)){ revert CrksLogic__AddressZero(); }
          // Get partneships addresses from the staking contract
          address[] memory partnerships = staking.getPartnerships();
          // Check if the partnership length is > partnershipsImages length
          if(partnerships.length > _partnershipsImages.length) {
               for(uint256 i = 0; i < partnerships.length - _partnershipsImages.length; i++) {
                    _partnershipsImages.push("");
               }
          }
          for(uint256 i = 0; i < partnerships.length; i++) {
               if(partnerships[i] == tokenAddress) {
                    _partnershipsImages[i] = image;
                    return;
               }
          }
      }

     /**
      * @dev Set the percentage for rank rewards.
      * @param perc The percentage array for CRO, NUTS, and PTT.
      */
      function setPercRankRewards(uint8[] memory perc) external onlyOwner {
          if(perc.length != 3) { revert CrksLogic__OverflowInput(); }
          contractBalancePercForRankRew = perc;
          }

     /**
      * @dev Increase the available CRO balance.
      * @param amount The amount to increase.
      */
     function increaseAvailableCroBalance(uint256 amount) external onlyOwner {
          availableCroBalance += amount;
     }

     /**
      * @dev Increase the available NUTS balance.
      * @param amount The amount to increase.
      */
     function increaseAvailableNutsBalance(uint256 amount) external onlyOwner {
          availableNutsBalance += amount;
     }

     /**
      * @dev Increase the available PTT balance for a partnership.
      * @param partnership The address of the partnership.
      * @param amount The amount to increase.
      */
     function increaseAvailablePttBalance(address partnership, uint256 amount) external onlyOwner {
          address[] memory partnerships = staking.getPartnerships();
          if (partnerships.length > availablePttBalance.length) {
               for (uint256 i = availablePttBalance.length; i < partnerships.length; i++) {
                    availablePttBalance.push(0);
               }
          }
          for (uint256 i = 0; i < partnerships.length; i++) {
               if (partnerships[i] == partnership) {
                    availablePttBalance[i] += amount;
                    return;
               }
          }
          revert CrksLogic__PartnershipsNotExist();
     }

     /**
      * @dev Set the available rank rewards balance.
      * @param cro The CRO balance.
      * @param nuts The NUTS balance.
      * @param ptt The PTT balance array.
      */
     function setAvaiableRankRewardsBalance(uint256 cro, uint256 nuts, uint256[] memory ptt) external onlyOwner {
          availableCroBalance = cro;
          availableNutsBalance = nuts;
          availablePttBalance = ptt;
     }

     /**
      * @dev Save the daily rank rewards information.
      */
     function saveRankRewardsDailyInfos() external onlyOwner {
          // Set up
          uint32 timestamp = uint32(block.timestamp);
          uint256 croBalance = availableCroBalance;
          uint256 nutsBalance = availableNutsBalance;
          uint256[] memory pttBalance = availablePttBalance;
          address[] memory _partnerships = staking.getPartnerships();

          if (_partnerships.length != availablePttBalance.length) {
               revert CrksLogic__DifferentArrayLength();
          }
          // Calculate the daily rewards (overwrite existing vars just to save gas)
          croBalance = croBalance * contractBalancePercForRankRew[0] / 100; // 5% of the contract balance
          nutsBalance = nutsBalance * contractBalancePercForRankRew[1] / 100; // "" ""
          if(_partnerships.length > 0) {
               // Save the balances of the _partnerships tokens
               pttBalance = new uint256[](_partnerships.length);
               for(uint i = 0; i < _partnerships.length; i++) {
                    if(_partnerships[i] != address(0)) {
                         // Check if the available balance is > 0
                         if(availablePttBalance[i] != 0) {
                              // Calculate the daily rewards
                              pttBalance[i] = availablePttBalance[i] * contractBalancePercForRankRew[2] / 100; // "" ""
                              // Update the available balances
                              availablePttBalance[i] -= pttBalance[i];
                         }
                    }
               }
          }
          // Update the available balances
          availableCroBalance -= croBalance;
          availableNutsBalance -= nutsBalance;
          // Save the daily rewards
          _rankRewardsDailyDistr.push(RankRewardsDailyDistr(timestamp, croBalance, nutsBalance, pttBalance, staking.getCounter("MEMBER"), staking.getCounter("HUSTLER"), staking.getCounter("STREET SOLDIER"), staking.getCounter("ENFORCER"), staking.getCounter("OFFICER"), staking.getCounter("CAPTAIN"), staking.getCounter("GENERAL"), staking.getCounter("GANG LEADER"), staking.getCounter("BOSS")));
     }

     /**
      * @dev Authorize the upgrade of the contract.
      * @param newImplementation The address of the new implementation.
      */
    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
        // This block is intentionally left empty
    }

}

File 11 of 33 : UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.0;

import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 *
 * _Available since v4.1._
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
    address private immutable __self = address(this);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        require(address(this) != __self, "Function must be called through delegatecall");
        require(_getImplementation() == __self, "Function must be called through active proxy");
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
        _;
    }

    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
        return _IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     */
    function upgradeTo(address newImplementation) external virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data, true);
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeTo} and {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal override onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

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

File 12 of 33 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

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

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

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

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

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

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initialized`
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initializing`
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.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 ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
    mapping(address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

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

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

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

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

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

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

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

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

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

File 15 of 33 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../extensions/draft-IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable {
    using AddressUpgradeable for address;

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

    function safeTransferFrom(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

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

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

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

File 16 of 33 : ERC20SnapshotUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/extensions/ERC20Snapshot.sol)

pragma solidity ^0.8.0;

import "../ERC20Upgradeable.sol";
import "../../../utils/ArraysUpgradeable.sol";
import "../../../utils/CountersUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev This contract extends an ERC20 token with a snapshot mechanism. When a snapshot is created, the balances and
 * total supply at the time are recorded for later access.
 *
 * This can be used to safely create mechanisms based on token balances such as trustless dividends or weighted voting.
 * In naive implementations it's possible to perform a "double spend" attack by reusing the same balance from different
 * accounts. By using snapshots to calculate dividends or voting power, those attacks no longer apply. It can also be
 * used to create an efficient ERC20 forking mechanism.
 *
 * Snapshots are created by the internal {_snapshot} function, which will emit the {Snapshot} event and return a
 * snapshot id. To get the total supply at the time of a snapshot, call the function {totalSupplyAt} with the snapshot
 * id. To get the balance of an account at the time of a snapshot, call the {balanceOfAt} function with the snapshot id
 * and the account address.
 *
 * NOTE: Snapshot policy can be customized by overriding the {_getCurrentSnapshotId} method. For example, having it
 * return `block.number` will trigger the creation of snapshot at the beginning of each new block. When overriding this
 * function, be careful about the monotonicity of its result. Non-monotonic snapshot ids will break the contract.
 *
 * Implementing snapshots for every block using this method will incur significant gas costs. For a gas-efficient
 * alternative consider {ERC20Votes}.
 *
 * ==== Gas Costs
 *
 * Snapshots are efficient. Snapshot creation is _O(1)_. Retrieval of balances or total supply from a snapshot is _O(log
 * n)_ in the number of snapshots that have been created, although _n_ for a specific account will generally be much
 * smaller since identical balances in subsequent snapshots are stored as a single entry.
 *
 * There is a constant overhead for normal ERC20 transfers due to the additional snapshot bookkeeping. This overhead is
 * only significant for the first transfer that immediately follows a snapshot for a particular account. Subsequent
 * transfers will have normal cost until the next snapshot, and so on.
 */

abstract contract ERC20SnapshotUpgradeable is Initializable, ERC20Upgradeable {
    function __ERC20Snapshot_init() internal onlyInitializing {
    }

    function __ERC20Snapshot_init_unchained() internal onlyInitializing {
    }
    // Inspired by Jordi Baylina's MiniMeToken to record historical balances:
    // https://github.com/Giveth/minime/blob/ea04d950eea153a04c51fa510b068b9dded390cb/contracts/MiniMeToken.sol

    using ArraysUpgradeable for uint256[];
    using CountersUpgradeable for CountersUpgradeable.Counter;

    // Snapshotted values have arrays of ids and the value corresponding to that id. These could be an array of a
    // Snapshot struct, but that would impede usage of functions that work on an array.
    struct Snapshots {
        uint256[] ids;
        uint256[] values;
    }

    mapping(address => Snapshots) private _accountBalanceSnapshots;
    Snapshots private _totalSupplySnapshots;

    // Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid.
    CountersUpgradeable.Counter private _currentSnapshotId;

    /**
     * @dev Emitted by {_snapshot} when a snapshot identified by `id` is created.
     */
    event Snapshot(uint256 id);

    /**
     * @dev Creates a new snapshot and returns its snapshot id.
     *
     * Emits a {Snapshot} event that contains the same id.
     *
     * {_snapshot} is `internal` and you have to decide how to expose it externally. Its usage may be restricted to a
     * set of accounts, for example using {AccessControl}, or it may be open to the public.
     *
     * [WARNING]
     * ====
     * While an open way of calling {_snapshot} is required for certain trust minimization mechanisms such as forking,
     * you must consider that it can potentially be used by attackers in two ways.
     *
     * First, it can be used to increase the cost of retrieval of values from snapshots, although it will grow
     * logarithmically thus rendering this attack ineffective in the long term. Second, it can be used to target
     * specific accounts and increase the cost of ERC20 transfers for them, in the ways specified in the Gas Costs
     * section above.
     *
     * We haven't measured the actual numbers; if this is something you're interested in please reach out to us.
     * ====
     */
    function _snapshot() internal virtual returns (uint256) {
        _currentSnapshotId.increment();

        uint256 currentId = _getCurrentSnapshotId();
        emit Snapshot(currentId);
        return currentId;
    }

    /**
     * @dev Get the current snapshotId
     */
    function _getCurrentSnapshotId() internal view virtual returns (uint256) {
        return _currentSnapshotId.current();
    }

    /**
     * @dev Retrieves the balance of `account` at the time `snapshotId` was created.
     */
    function balanceOfAt(address account, uint256 snapshotId) public view virtual returns (uint256) {
        (bool snapshotted, uint256 value) = _valueAt(snapshotId, _accountBalanceSnapshots[account]);

        return snapshotted ? value : balanceOf(account);
    }

    /**
     * @dev Retrieves the total supply at the time `snapshotId` was created.
     */
    function totalSupplyAt(uint256 snapshotId) public view virtual returns (uint256) {
        (bool snapshotted, uint256 value) = _valueAt(snapshotId, _totalSupplySnapshots);

        return snapshotted ? value : totalSupply();
    }

    // Update balance and/or total supply snapshots before the values are modified. This is implemented
    // in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, amount);

        if (from == address(0)) {
            // mint
            _updateAccountSnapshot(to);
            _updateTotalSupplySnapshot();
        } else if (to == address(0)) {
            // burn
            _updateAccountSnapshot(from);
            _updateTotalSupplySnapshot();
        } else {
            // transfer
            _updateAccountSnapshot(from);
            _updateAccountSnapshot(to);
        }
    }

    function _valueAt(uint256 snapshotId, Snapshots storage snapshots) private view returns (bool, uint256) {
        require(snapshotId > 0, "ERC20Snapshot: id is 0");
        require(snapshotId <= _getCurrentSnapshotId(), "ERC20Snapshot: nonexistent id");

        // When a valid snapshot is queried, there are three possibilities:
        //  a) The queried value was not modified after the snapshot was taken. Therefore, a snapshot entry was never
        //  created for this id, and all stored snapshot ids are smaller than the requested one. The value that corresponds
        //  to this id is the current one.
        //  b) The queried value was modified after the snapshot was taken. Therefore, there will be an entry with the
        //  requested id, and its value is the one to return.
        //  c) More snapshots were created after the requested one, and the queried value was later modified. There will be
        //  no entry for the requested id: the value that corresponds to it is that of the smallest snapshot id that is
        //  larger than the requested one.
        //
        // In summary, we need to find an element in an array, returning the index of the smallest value that is larger if
        // it is not found, unless said value doesn't exist (e.g. when all values are smaller). Arrays.findUpperBound does
        // exactly this.

        uint256 index = snapshots.ids.findUpperBound(snapshotId);

        if (index == snapshots.ids.length) {
            return (false, 0);
        } else {
            return (true, snapshots.values[index]);
        }
    }

    function _updateAccountSnapshot(address account) private {
        _updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account));
    }

    function _updateTotalSupplySnapshot() private {
        _updateSnapshot(_totalSupplySnapshots, totalSupply());
    }

    function _updateSnapshot(Snapshots storage snapshots, uint256 currentValue) private {
        uint256 currentId = _getCurrentSnapshotId();
        if (_lastSnapshotId(snapshots.ids) < currentId) {
            snapshots.ids.push(currentId);
            snapshots.values.push(currentValue);
        }
    }

    function _lastSnapshotId(uint256[] storage ids) private view returns (uint256) {
        if (ids.length == 0) {
            return 0;
        } else {
            return ids[ids.length - 1];
        }
    }

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

File 17 of 33 : ERC20PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Pausable.sol)

pragma solidity ^0.8.0;

import "../ERC20Upgradeable.sol";
import "../../../security/PausableUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev ERC20 token with pausable token transfers, minting and burning.
 *
 * Useful for scenarios such as preventing trades until the end of an evaluation
 * period, or having an emergency switch for freezing all token transfers in the
 * event of a large bug.
 */
abstract contract ERC20PausableUpgradeable is Initializable, ERC20Upgradeable, PausableUpgradeable {
    function __ERC20Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __ERC20Pausable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {ERC20-_beforeTokenTransfer}.
     *
     * Requirements:
     *
     * - the contract must not be paused.
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, amount);

        require(!paused(), "ERC20Pausable: token transfer while paused");
    }

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

File 18 of 33 : IUniswapV2Router02.sol
pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

File 19 of 33 : IUniswapV2Factory.sol
pragma solidity >=0.5.0;

interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

File 20 of 33 : IUniswapV2Pair.sol
pragma solidity >=0.5.0;

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;

    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}

File 21 of 33 : IScoreArray.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

interface IScoreArray {
    function populate(uint256[] memory _array) external;
    function return_score(uint256 _tokenId) external view returns (uint);
}

File 22 of 33 : draft-IERC1822Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822ProxiableUpgradeable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

File 23 of 33 : ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)

pragma solidity ^0.8.2;

import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import "../utils/Initializable.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 *
 * @custom:oz-upgrades-unsafe-allow delegatecall
 */
abstract contract ERC1967UpgradeUpgradeable is Initializable {
    function __ERC1967Upgrade_init() internal onlyInitializing {
    }

    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
    }
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Returns the current implementation address.
     */
    function _getImplementation() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
        StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Perform implementation upgrade
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Perform implementation upgrade with additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCall(
        address newImplementation,
        bytes memory data,
        bool forceCall
    ) internal {
        _upgradeTo(newImplementation);
        if (data.length > 0 || forceCall) {
            _functionDelegateCall(newImplementation, data);
        }
    }

    /**
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCallUUPS(
        address newImplementation,
        bytes memory data,
        bool forceCall
    ) internal {
        // Upgrades from old implementations will perform a rollback test. This test requires the new
        // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
        // this special case will break upgrade paths from old UUPS implementation to new ones.
        if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
            _setImplementation(newImplementation);
        } else {
            try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
                require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
            } catch {
                revert("ERC1967Upgrade: new implementation is not UUPS");
            }
            _upgradeToAndCall(newImplementation, data, forceCall);
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Returns the current admin.
     */
    function _getAdmin() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");
        StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     */
    function _changeAdmin(address newAdmin) internal {
        emit AdminChanged(_getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
     */
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Emitted when the beacon is upgraded.
     */
    event BeaconUpgraded(address indexed beacon);

    /**
     * @dev Returns the current beacon.
     */
    function _getBeacon() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        require(
            AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
            "ERC1967: beacon implementation is not a contract"
        );
        StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }

    /**
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
     *
     * Emits a {BeaconUpgraded} event.
     */
    function _upgradeBeaconToAndCall(
        address newBeacon,
        bytes memory data,
        bool forceCall
    ) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);
        if (data.length > 0 || forceCall) {
            _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
        }
    }

    /**
     * @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) private returns (bytes memory) {
        require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed");
    }

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

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

        return account.code.length > 0;
    }

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

File 26 of 33 : IERC20MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

File 28 of 33 : ArraysUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Arrays.sol)

pragma solidity ^0.8.0;

import "./StorageSlotUpgradeable.sol";
import "./math/MathUpgradeable.sol";

/**
 * @dev Collection of functions related to array types.
 */
library ArraysUpgradeable {
    using StorageSlotUpgradeable for bytes32;

    /**
     * @dev Searches a sorted `array` and returns the first index that contains
     * a value greater or equal to `element`. If no such index exists (i.e. all
     * values in the array are strictly less than `element`), the array length is
     * returned. Time complexity O(log n).
     *
     * `array` is expected to be sorted in ascending order, and to contain no
     * repeated elements.
     */
    function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        if (array.length == 0) {
            return 0;
        }

        uint256 low = 0;
        uint256 high = array.length;

        while (low < high) {
            uint256 mid = MathUpgradeable.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds down (it does integer division with truncation).
            if (unsafeAccess(array, mid).value > element) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
        if (low > 0 && unsafeAccess(array, low - 1).value == element) {
            return low - 1;
        } else {
            return low;
        }
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlotUpgradeable.AddressSlot storage) {
        bytes32 slot;
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0, arr.slot)
            slot := add(keccak256(0, 0x20), pos)
        }
        return slot.getAddressSlot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlotUpgradeable.Bytes32Slot storage) {
        bytes32 slot;
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0, arr.slot)
            slot := add(keccak256(0, 0x20), pos)
        }
        return slot.getBytes32Slot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlotUpgradeable.Uint256Slot storage) {
        bytes32 slot;
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0, arr.slot)
            slot := add(keccak256(0, 0x20), pos)
        }
        return slot.getUint256Slot();
    }
}

File 29 of 33 : CountersUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library CountersUpgradeable {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

File 30 of 33 : IUniswapV2Router01.sol
pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

File 31 of 33 : IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.0;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeaconUpgradeable {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

File 32 of 33 : StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
 */
library StorageSlotUpgradeable {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }
}

File 33 of 33 : MathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

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

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

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10**64) {
                value /= 10**64;
                result += 64;
            }
            if (value >= 10**32) {
                value /= 10**32;
                result += 32;
            }
            if (value >= 10**16) {
                value /= 10**16;
                result += 16;
            }
            if (value >= 10**8) {
                value /= 10**8;
                result += 8;
            }
            if (value >= 10**4) {
                value /= 10**4;
                result += 4;
            }
            if (value >= 10**2) {
                value /= 10**2;
                result += 2;
            }
            if (value >= 10**1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}

Settings
{
  "remappings": [
    "/forge-std/=lib/forge-std/src/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/contracts-upgradeable/",
    "@uniswap/v2-core/=lib/uniswap/v2-core/",
    "@uniswap/v2-periphery/=lib/uniswap/v2-periphery/",
    "contracts-upgradeable/=lib/contracts-upgradeable/",
    "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "uniswap/=lib/uniswap/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 125
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "viaIR": true,
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"croRew","type":"uint256"},{"internalType":"uint256","name":"nutsRew","type":"uint256"}],"name":"CrksStak__ClaimRankRewardsFirst","type":"error"},{"inputs":[{"internalType":"uint256","name":"toClaim","type":"uint256"}],"name":"CrksStak__ClaimRewardsFirst","type":"error"},{"inputs":[],"name":"CrksStak__InvalidAddress","type":"error"},{"inputs":[],"name":"CrksStak__InvalidAmount","type":"error"},{"inputs":[],"name":"CrksStak__InvalidERC20token","type":"error"},{"inputs":[],"name":"CrksStak__InvalidStakingOption","type":"error"},{"inputs":[],"name":"CrksStak__NoNftStakes","type":"error"},{"inputs":[],"name":"CrksStak__NotEnoughAllowance","type":"error"},{"inputs":[],"name":"CrksStak__NotEnoughBalance","type":"error"},{"inputs":[],"name":"CrksStak__NotEnoughContractBalance","type":"error"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"}],"name":"CrksStak__NotTheNftOwner","type":"error"},{"inputs":[],"name":"CrksStak__PartnershipExists","type":"error"},{"inputs":[],"name":"CrksStak__PartnershipNotExists","type":"error"},{"inputs":[],"name":"CrksStak__StakingPeriodNotOver","type":"error"},{"inputs":[],"name":"CrksStak__TransferFailed","type":"error"},{"inputs":[],"name":"CrksStak__ZeroRewardsToClaim","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"uncappedApr","type":"uint256"}],"name":"AprUncapped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint16","name":"amount","type":"uint16"},{"indexed":false,"internalType":"uint16[]","name":"nftIds","type":"uint16[]"}],"name":"CrklNftStaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint16","name":"amount","type":"uint16"},{"indexed":false,"internalType":"uint16[]","name":"nftIds","type":"uint16[]"}],"name":"CrklNftUnstaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"CrksClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"CrksCompounded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"stakedFor","type":"uint32"}],"name":"CrksStakeOverwritten","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"stakedFor","type":"uint32"}],"name":"CrksStaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"CrksUnstaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"croRewards","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nutsRewards","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"pttRewards","type":"uint256[]"}],"name":"RankRewardsClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"addPartnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cappedPercAPR","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"compoundPerc","type":"uint8"}],"name":"claimAndCompCrks","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimRankRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"contractBalancePercForRankRew","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"crksBalanceForRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"crksTotalStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositCrooks","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getActualUserAlignBonus","outputs":[{"internalType":"uint256","name":"apr","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAlignBonusInfo","outputs":[{"internalType":"uint256","name":"crksReq","type":"uint256"},{"internalType":"uint16","name":"crklReq","type":"uint16"},{"internalType":"uint24","name":"aprBonus","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"rankName","type":"string"}],"name":"getCounter","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getCrksClaims","outputs":[{"components":[{"internalType":"uint256","name":"totClaimed","type":"uint256"},{"internalType":"uint32","name":"lastClaimTime","type":"uint32"},{"internalType":"uint256","name":"totCompounded","type":"uint256"},{"internalType":"uint32","name":"lastCompTime","type":"uint32"},{"internalType":"uint32","name":"lastInfoIndex","type":"uint32"}],"internalType":"struct CrooksStakingV2.CrksClaim","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getCrksStake","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint32","name":"stakedAt","type":"uint32"},{"internalType":"uint8","name":"stakedFor","type":"uint8"},{"internalType":"uint256","name":"stakedUntil","type":"uint256"},{"internalType":"uint32","name":"infoIndex","type":"uint32"}],"internalType":"struct CrooksStakingV2.CrksStake","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getLastNftStake","outputs":[{"components":[{"internalType":"uint16","name":"amount","type":"uint16"},{"internalType":"uint16[]","name":"nftIds","type":"uint16[]"},{"internalType":"uint32","name":"lastChange","type":"uint32"}],"internalType":"struct CrooksStakingV2.NftStake","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLastRankRewDailyDistr","outputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getNftStakes","outputs":[{"components":[{"internalType":"uint16","name":"amount","type":"uint16"},{"internalType":"uint16[]","name":"nftIds","type":"uint16[]"},{"internalType":"uint32","name":"lastChange","type":"uint32"}],"internalType":"struct CrooksStakingV2.NftStake[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPartnerships","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"rankName","type":"string"}],"name":"getRankInfo","outputs":[{"internalType":"uint256","name":"minStakedAmount","type":"uint256"},{"internalType":"uint16","name":"minLegendsAmount","type":"uint16"},{"internalType":"uint24","name":"aprBonus","type":"uint24"},{"internalType":"uint8","name":"rankDistribution","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRankRewDailyDistr","outputs":[{"components":[{"internalType":"uint32","name":"timestamp","type":"uint32"},{"internalType":"uint256","name":"croRewards","type":"uint256"},{"internalType":"uint256","name":"nutsRewards","type":"uint256"},{"internalType":"uint256[]","name":"pttRewards","type":"uint256[]"},{"internalType":"uint16","name":"nOfMembers","type":"uint16"},{"internalType":"uint16","name":"nOfHustlers","type":"uint16"},{"internalType":"uint16","name":"nOfStreetSoldiers","type":"uint16"},{"internalType":"uint16","name":"nOfEnforcers","type":"uint16"},{"internalType":"uint16","name":"nOfOfficers","type":"uint16"},{"internalType":"uint16","name":"nOfCaptains","type":"uint16"},{"internalType":"uint16","name":"nOfGenerals","type":"uint16"},{"internalType":"uint16","name":"nOfGangLeaders","type":"uint16"},{"internalType":"uint16","name":"nOfBosses","type":"uint16"}],"internalType":"struct CrooksStakingV2.RankRewardsDailyDistr[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getRankRewardsClaim","outputs":[{"components":[{"internalType":"uint256","name":"croClaimed","type":"uint256"},{"internalType":"uint256","name":"nutsClaimed","type":"uint256"},{"internalType":"uint256[]","name":"pttClaimed","type":"uint256[]"},{"internalType":"uint32","name":"lastClaimTime","type":"uint32"}],"internalType":"struct CrooksStakingV2.RankRewardsClaim","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_infoIndex","type":"uint32"}],"name":"getStakingRule","outputs":[{"components":[{"internalType":"uint256","name":"maxAmount","type":"uint256"},{"internalType":"uint8","name":"minStakingPeriod","type":"uint8"},{"internalType":"uint16","name":"maxStakingPeriod","type":"uint16"},{"internalType":"uint24","name":"APRxMonths","type":"uint24"},{"internalType":"uint32","name":"lastChange","type":"uint32"}],"internalType":"struct CrooksStakingV2.StakingRules","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getUC_perc","outputs":[{"internalType":"uint8","name":"aprUC","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getUltimateUser","outputs":[{"components":[{"internalType":"bool","name":"uC","type":"bool"},{"internalType":"uint32","name":"fromTimestamp","type":"uint32"},{"internalType":"uint32","name":"toTimestamp","type":"uint32"}],"internalType":"struct CrooksStakingV2.UserUltimate","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"infoIndex","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"crooksAddress","type":"address"},{"internalType":"address","name":"nutsAddress","type":"address"},{"internalType":"address","name":"legendsAddress","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"removePartnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"saveRankRewardsDailyInfos","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"crksReq","type":"uint256"},{"internalType":"uint16","name":"crklReq","type":"uint16"},{"internalType":"uint24","name":"aprBonus","type":"uint24"}],"name":"setAlignBonus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"croPerc","type":"uint8"},{"internalType":"uint8","name":"nutsPerc","type":"uint8"},{"internalType":"uint8","name":"pttPerc","type":"uint8"}],"name":"setContractBalancePercForRankRew","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"rankName","type":"string"},{"internalType":"uint256","name":"minStakedAmount","type":"uint256"},{"internalType":"uint16","name":"minLegendsAmount","type":"uint16"},{"internalType":"uint24","name":"aprBonus","type":"uint24"},{"internalType":"uint8","name":"rankDistribution","type":"uint8"}],"name":"setRank","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"stakingLogicsAddress","type":"address"}],"name":"setStakingLogicsAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"maxAmount","type":"uint256"},{"internalType":"uint8","name":"minStakingPeriod","type":"uint8"},{"internalType":"uint16","name":"maxStakingPeriod","type":"uint16"},{"internalType":"uint24","name":"aprXmonthly","type":"uint24"}],"name":"setStakingRules","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"setUC_address","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"aprUC","type":"uint8"}],"name":"setUC_apr","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint8","name":"stakedFor","type":"uint8"}],"name":"stakeCrks","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint16[]","name":"nftIds","type":"uint16[]"}],"name":"stakeNft","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalCrksRewarded","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalCroRewarded","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalNutsRewarded","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"ultimateAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"aprPerc","type":"uint256"},{"internalType":"uint256","name":"crksAmounToUncap","type":"uint256"}],"name":"uncapApr","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"uncapOnePercAPRinUSDT","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unstakeCrks","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16[]","name":"ids","type":"uint16[]"}],"name":"unstakeNft","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userUncappedAPR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a0806040523460d857306080526000549060ff8260081c166086575060ff80821610604c575b604051615f9490816100de82396080518181816140d001528181614201015261464a0152f35b60ff90811916176000557f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498602060405160ff8152a1386026565b62461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b6064820152608490fd5b600080fdfe6080604052600436101561001b575b361561001957600080fd5b005b60003560e01c8063067262de14614ece578063150b7a0214614e5f578063163f2c2214614e235780631703a44d14614d025780631e5cd51a14614b9157806322f8a23314614b7257806325458b3114614aa75780632e7b263514614a105780632fbd1ea2146149d65780633475122b146149075780633659cfe61461462c5780633e3d63fa14614602578063487ae0d714614557578063491763351461450957806349571a5e146144c55780634f1ef286146141b75780634f238b791461417c57806352d1902d146140bd5780635c975abb1461409a5780635d8f767414613d4457806366cb402914613bb257806367e1947214613b8b5780636dfa125c14613b66578063715018a614613b0957806372038abb14613a5757806376caca1a14613a07578063850c5598146136525780638565d240146132285780638904476714612fe45780638da5cb5b14612fbb5780638dceeeec14612f0e578063a1db978214612e13578063a263581c14612df1578063a2d56a3c14612d61578063a7d742ba14612d38578063abd7334114612be9578063ada8b78614612bca578063af399e3614612ade578063b980d799146129f3578063c0c53b8b14611ef4578063d47cc5f714611e4b578063da17349e14611e26578063dcd048601461191a578063e1821cbc14611867578063e18b89851461118d578063e628c8771461116e578063e67cc38e146110a8578063e94cb10714611089578063ed35918f1461106a578063ed97a02014610b06578063f14210a614610a91578063f164c0d5146109e5578063f2fde38b14610958578063f6a684af1461083c5763fa43bf900361000e573461082357600036600319011261082357610296615cb8565b61012e546040516370a0823160e01b81523060048201524791602090829060249082906001600160a01b03165afa908115610830576000916107f9575b50606090600061013854156107e5576102fe60208261013860649452209460ff6000965416906159a5565b049161013854600110156107d1576101388452606461032b602086209360ff6001955460081c16906159a5565b0490610131548061069e575b5061ffff60266040516526a2a6a122a960d11b815261014560068201522054169361ffff602760405166242aa9aa2622a960c91b815261014560078201522054169361ffff602e6040516d29aa2922a2aa1029a7a62224a2a960911b8152610145600e8201522054169161ffff60286040516722a72327a921a2a960c11b815261014560088201522054169061ffff60276040516627a32324a1a2a960c91b815261014560078201522054169661ffff60276040516621a0a82a20a4a760c91b815261014560078201522054169161ffff60276040516611d1539154905360ca1b815261014560078201522054169461ffff602b6040516a23a0a723902622a0a222a960a91b8152610145600b8201522054169761ffff602460405163424f535360e01b81526101456004820152205416996040519361047685615042565b4263ffffffff168552602085019081526040850191825260608501928352608085019d8e5260a0850195865260c08501998a5260e0850197885261010085019c8d526101208501968752610140850198895261016085019a8b5261018085019b8c5261013d54600160401b811015610689578060016104f9920161013d55615c97565b9590956106745751855463ffffffff191663ffffffff919091161785555160018501555160028401555180519060038401906001600160401b03831161066057600160401b8311610660579060208f928254858455808610610646575b500191528d60208120905b83811061063357505050505061ffff60048192019a51161661ffff198a54161789555167ffff00000000000065ffff000000008a54965160201b16935160301b169761ffff60401b905160401b169161ffff60501b905160501b169361ffff60601b905160601b169561ffff60701b905160701b169661ffff60801b905160801b169761ffff60801b199561ffff60701b199461ffff60601b199361ffff60501b199263ffff000061ffff60401b199260101b169067ffffffffffff0000191617161716171617161716171717905580f35b8490602084519401938184015501610561565b83855282852061065a9181019087016159b8565b38610556565b634e487b7160e01b8f52604160045260248ffd5b50634e487b7160e01b8f5260048f905260248ffd5b50634e487b7160e01b8f52604160045260248ffd5b90506106a9816151b3565b9083865b8281106106bb575050610337565b6106c4816155fe565b905460039190911b1c6001600160a01b03166106e3575b0184906106ad565b9050602460206106f2836155fe565b90546040516370a0823160e01b81523060048201529384929091839160031b1c6001600160a01b03165afa9081156107c6578891610791575b506107368285615991565b526107418184615991565b51610138546002101561077d5790606461076c87936101388b5260ff60208c205460101c16906159a5565b046107778286615991565b526106db565b634e487b7160e01b88526032600452602488fd5b90506020813d82116107be575b816107ab6020938361505e565b810103126107ba57513861072b565b8780fd5b3d915061079e565b6040513d8a823e3d90fd5b634e487b7160e01b84526032600452602484fd5b634e487b7160e01b81526032600452602490fd5b90506020813d602011610828575b816108146020938361505e565b810103126108235751386102d3565b600080fd5b3d9150610807565b6040513d6000823e3d90fd5b346108235760003660031901126108235761013d5460001981019081116109425761087161086b602092615c97565b506158e7565b63ffffffff815116908281015160408201519160608101519261ffff6080830151169361ffff60a08401511661ffff60c08501511661ffff60e0860151169061ffff610100870151169261090b61ffff610120890151169561ffff6101408a0151169761ffff610180816101608d0151169b0151169a6040519e8f9e8f908152015260408d01526101a060608d01526101a08c0190614fbd565b9860808b015260a08a015260c089015260e08801526101008701526101208601526101408501526101608401526101808301520390f35b634e487b7160e01b600052601160045260246000fd5b3461082357602036600319011261082357610971614f2f565b610979615cb8565b6001600160a01b038116156109915761001990615daa565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b34610823576020366003190112610823576004356001600160401b03811161082357610a2f6020610a1c60809336906004016150d1565b81604051938285809451938492016157ce565b81016101418152030190206060604051610a4881614ff1565b600183549384835201549061ffff82169081602082015260ff62ffffff8460101c169384604084015260281c169384910152604051938452602084015260408301526060820152f35b3461082357602036600319011261082357600435610aad615cb8565b8015610af557478111610ae457600080808093335af1610acb615be0565b5015610ad357005b632185bbe960e01b60005260046000fd5b63280bb89b60e11b60005260046000fd5b632eb4702560e21b60005260046000fd5b3461082357610b1436615117565b610b1c615d10565b610b24615d54565b61ffff815116336000526101426020526040600020543360005261013f602052604060002054928215610af55761012f546001600160a01b0316939260005b61ffff811682811015610c345761ffff610b7d8286615991565b516040516331a9108f60e11b8152911660048201526020816024818b5afa90811561083057600091610bec575b50336001600160a01b0390911603610bc9575060010161ffff16610b63565b610bd661ffff9185615991565b5116635b7f003760e11b60005260045260246000fd5b6020813d8211610c2c575b81610c046020938361505e565b81010312610c285751906001600160a01b0382168203610c25575088610baa565b80fd5b5080fd5b3d9150610bf7565b505060405163e985e9c560e01b815284908490602081898180610c5b303360048401615633565b03915afa9081156108305760009161103b575b501561102a5780158015610f6d575b15610e6c5750610cbb604051610c928161500c565b83815284602082015263ffffffff421660408201523360005261014260205260406000206159cf565b33600052610142602052604060002054610da4575b5060005b61ffff81169082821015610d675761012f546001600160a01b03169161ffff90610cfe9086615991565b511691803b1561082357604051632142170760e11b815233600482015230602482015261ffff9390931660448401526000908390606490829084905af19081156108305761ffff92600192610d56575b500116610cd4565b6000610d619161505e565b85610d4e565b60405133907f0ec1e973d17a791ac1d35b376dcaa8acdc59097156eadb6860e2d78bab0b3dfb9080610d9a888883615b97565b0390a2600160fb55005b6000610df091610db333615560565b610130549051604051637dd46cc160e01b8152600481019390935261ffff166024830152909283916001600160a01b031690829081906044820190565b03915afa90811561083057610e1e91602091600091610e49575b5081604051938285809451938492016157ce565b810161014581520301902061ffff610e3881835416615b84565b1661ffff1982541617905582610cd0565b610e6691503d806000833e610e5e818361505e565b810190615878565b85610e0a565b929092336000526101426020526040600020600019820191821161094257610e9d91610e97916151f2565b50615224565b908261ffff8351160161ffff81116109425761ffff16825263ffffffff421660408301526020820192835194610edc610ed7838851615687565b6151b3565b9360005b8751811015610f0c578061ffff610ef96001938b615991565b5116610f058289615991565b5201610ee0565b509295949093919460005b868110610f4057505090610f3b9291523360005261014260205260406000206159cf565b610cbb565b8061ffff610f506001938b615991565b5116610f66610f60838651615687565b87615991565b5201610f17565b610fb86000610f7b33615560565b610130549051604051637dd46cc160e01b81526004810188905261ffff90911660248201529283916001600160a01b031690829081906044820190565b03915afa90811561083057610fe59160209160009161100f575081604051938285809451938492016157ce565b810161014581520301902061ffff610fff818354166158d6565b1661ffff19825416179055610c7d565b61102491503d806000833e610e5e818361505e565b88610e0a565b6323403ae760e11b60005260046000fd5b61105d915060203d602011611063575b611055818361505e565b81019061564d565b85610c6e565b503d61104b565b3461082357600036600319011261082357602061013254604051908152f35b3461082357600036600319011261082357602061013454604051908152f35b34610823576080366003190112610823576110c1614f1f565b6110c9615106565b906110d26151a1565b6110da615cb8565b610137549263ffffffff84169363ffffffff85146109425763ffffffff1916600194850163ffffffff1690811761013755600090815261013e602052604090206004358155909301805469ffffffffffffffffffff191660ff939093169290921760089390931b62ffff00169290921760189290921b65ffffff00000016919091174260301b63ffffffff60301b16179055005b3461082357600036600319011261082357602061013354604051908152f35b6040366003190112610823576004356111a4614f1f565b906111ad615d10565b6111b5615d54565b63ffffffff610137541660005261013e6020526040600020604051926111da84615027565b6001825492838652015491602085019060ff8416825263ffffffff604087019461ffff8160081c16865262ffffff8160181c16606089015260301c166080870152841590811561185d575b50610af5575160ff828116939116831090811561184e575b5061183d5761012d546040516370a0823160e01b81523360048201526001600160a01b0390911690602081602481855afa9081156108305760009161180b575b5084116117fa5760206040518092636eb1769f60e11b825281806112a5303360048401615633565b03915afa908115610830576000916117c8575b50831161102a573360005261013f6020526040600020933360005261014260205260406000205415159283611709575b8554156115f057508454906112fd8583615687565b905110610af55761013054604051638ca1a34560e01b81523360048201526001600160a01b0390911690602081602481855afa908115610830576000916115be575b50806115aa57506000602491604051928380926344d7b31560e11b82523360048301525afa90811561083057600090600092611583575b50801580159061157a575b6115635750508361139191615687565b845560018401805463ffffffff19164263ffffffff1617908190556228206f602082901c60ff168181029181159183041417156109425763ffffffff6113d79216615687565b60028501556101375460038501805463ffffffff191663ffffffff9290921691909117905561012d546040516323b872dd60e01b81529060209082906001600160a01b03168160008161142f8a303360048501615665565b03925af190811561083057600091611544575b5015610ad3576040805184815260ff92909216602083015233917f5edc2559845a9a5b7f90429212d6be99f0394809a7b970fbc043c4ae37424e8c9190a25b61149e575b6114939061013254615687565b61013255600160fb55005b60006114eb926114ad33615560565b6101305491549051604051637dd46cc160e01b8152600481019290925261ffff1660248201529384916001600160a01b031690829081906044820190565b03915afa801561083057602061151a9161149394600091610e49575081604051938285809451938492016157ce565b810161014581520301902061ffff61153481835416615b84565b1661ffff19825416179055611486565b61155d915060203d60201161106357611055818361505e565b85611442565b634aa25a9d60e11b60005260045260245260446000fd5b50811515611381565b90506115a291503d806000833e61159a818361505e565b8101906157f1565b509087611376565b632f320e8f60e21b60005260045260246000fd5b906020823d6020116115e8575b816115d86020938361505e565b81010312610c255750518761133f565b3d91506115cb565b84865560018601805464ffffffffff19164263ffffffff16908117602086901b64ff00000000161790915591506228206f80820291801590830490911417156109425761163c91615687565b60028501556101375460038501805463ffffffff191663ffffffff9290921691909117905561012d546040516323b872dd60e01b81529060209082906001600160a01b0316816000816116948a303360048501615665565b03925af1908115610830576000916116ea575b5015610ad3576040805184815260ff92909216602083015233917ff55a761e85d1956c857a72e717bf2f52dcded09af3176bc37dad5290c1b82eeb9190a2611481565b611703915060203d60201161106357611055818361505e565b856116a7565b611756600061171733615560565b6101305489549151604051637dd46cc160e01b8152600481019390935261ffff166024830152909283916001600160a01b031690829081906044820190565b03915afa90811561083057611783916020916000916117ad575081604051938285809451938492016157ce565b810161014581520301902061ffff61179d818354166158d6565b1661ffff198254161790556112e8565b6117c291503d806000833e610e5e818361505e565b89610e0a565b90506020813d6020116117f2575b816117e36020938361505e565b810103126108235751856112b8565b3d91506117d6565b630233bbe560e61b60005260046000fd5b90506020813d602011611835575b816118266020938361505e565b8101031261082357518661127d565b3d9150611819565b6305ea81b560e11b60005260046000fd5b61ffff9150511682118561123d565b9050841186611225565b346108235760203660031901126108235760043563ffffffff8116809103610823576118916157a3565b5060005261013e60205260a0604060002063ffffffff6040516118b381615027565b62ffffff600184549485845201549161ffff6020820160ff8516815260ff6040840191838760081c1683528760806060870196888a60181c168852019760301c16875260405198895251166020880152511660408601525116606084015251166080820152f35b3461082357602036600319011261082357611933614f0f565b61193b615d10565b611943615d54565b336000526101406020526040600020903360005261013f6020526040600020913360005261014360205260406000209260018060a01b0361013054169060405190638ca1a34560e01b8252336004830152602082602481865afa91821561083057600092611df2575b5081948215611de15760ff1660648111610af557610133548311610ae45780611b0c575b5050505081611a34575b50816119fb925460ff811680611a1b575b611a06575b505061013454615687565b61013455600160fb55005b68ffffffffffffffffff1916905582806119f0565b5063ffffffff8160281c1663ffffffff421610156119eb565b80611a428360019354615687565b815501805463ffffffff19164263ffffffff1617905561013354611a679082906151e5565b6101335561012d5460405163a9059cbb60e01b81523360048201526024810183905290602090829060449082906000906001600160a01b03165af190811561083057600091611aed575b5015610ad3576119fb916040518281527f27e57bc8b08a3f45f6d9bb3847d286bc94ae50ed60734163713e34521d51aa9e60203392a2916119da565b611b06915060203d60201161106357611055818361505e565b83611ab1565b90919294506040516344d7b31560e11b8152336004820152600081602481895afa90811561083057600090600092611dc2575b508015801590611db9575b6115635750503360005261014260205260406000205415159485611d00575b50611b76606491846159a5565b0491611b83825484615687565b63ffffffff610137541660005261013e60205260406000205410610af55782611bab916151e5565b9360028401611bbb848254615687565b905560038401805463ffffffff19164263ffffffff161790558154611be1908490615687565b8255611bf083610133546151e5565b61013355611c018361013254615687565b61013255611c40575b506040519081527fb6296e8aa12725250cdc0076d6ff23122ef1f56621eb33ea8c149ba206e1751460203392a2838080806119d0565b6000611c8d91611c4f33615560565b6101305491549051604051637dd46cc160e01b8152600481019290925261ffff1660248201529283916001600160a01b031690829081906044820190565b03915afa90811561083057611cba91602091600091611ce5575081604051938285809451938492016157ce565b810161014581520301902061ffff611cd481835416615b84565b1661ffff1982541617905584611c0a565b611cfa91503d806000833e610e5e818361505e565b87610e0a565b6000611d4091611d0f33615560565b85549051604051637dd46cc160e01b8152600481019290925261ffff16602482015292839190829081906044820190565b03915afa91821561083057611d726020606494611b7694600091611d9e575081604051938285809451938492016157ce565b810161014581520301902061ffff611d8c818354166158d6565b1661ffff198254161790559150611b69565b611db391503d806000833e610e5e818361505e565b8b610e0a565b50811515611b4a565b9050611dd991503d806000833e61159a818361505e565b509088611b3f565b63294bf2bb60e11b60005260046000fd5b90916020823d602011611e1e575b81611e0d6020938361505e565b81010312610c2557505190866119ac565b3d9150611e00565b3461082357600036600319011261082357602060ff61013c5460a01c16604051908152f35b3461082357602036600319011261082357611e64614f2f565b611e6c615cb8565b6001600160a01b031660008181526101436020526040902061013c80546001600160a01b031916909217909155805464ffffffffff191642600890811b64ffffffff0016919091176001178083556228206f911c63ffffffff1690810190811061094257815468ffffffff0000000000191660289190911b68ffffffff000000000016179055005b3461082357606036600319011261082357611f0d614f2f565b611f15614f45565b6044356001600160a01b0381169190829003610823576000549260ff8460081c1615938480956129e6575b80156129cf575b156129735760ff19811660011760005584612961575b50611f7860ff60005460081c16611f7381615df3565b615df3565b611f8133615daa565b611fc560ff60005460081c16611f9681615df3565b611f9f81615df3565b60ff1960c9541660c955611fb281615df3565b611fbb81615df3565b600160fb55615df3565b61012d80546001600160a01b03199081166001600160a01b039384161790915561012e805482169390921692909217905561012f8054909116919091179055610137805463ffffffff1916905560006101328190556101338190556101348190556101358190556101365560405161203c8161500c565b60058152600560208201526005604082015261013854600361013855806003106128fa575b50610138600052602060002060009160005b600381106128cc57505055610139805463ffffffff1916630186a00a1790556101375463ffffffff16600090815261013e602052604090206a02116545850052128000008155600101805469ffffffffffffffffffff19164260301b63ffffffff60301b16176401f40030011790556064604080516120f18161500c565b683635c9adc5dea000008082526001602083015291019190915261013a5561013b805464ffffffffff191662640001179055604080519081018181106001600160401b038211176128b65760199160209160405260008152015260018060a01b031961013c541661013c55601960a01b60ff60a01b1961013c54161761013c55602860405167141493d4d41150d560c21b815261014560088201522061ffff19815416905560266040516526a2a6a122a960d11b815261014560068201522061ffff198154169055602760405166242aa9aa2622a960c91b815261014560078201522061ffff198154169055602e6040516d29aa2922a2aa1029a7a62224a2a960911b8152610145600e8201522061ffff19815416905560286040516722a72327a921a2a960c11b815261014560088201522061ffff19815416905560276040516627a32324a1a2a960c91b815261014560078201522061ffff19815416905560276040516621a0a82a20a4a760c91b815261014560078201522061ffff19815416905560276040516611d1539154905360ca1b815261014560078201522061ffff198154169055602b6040516a23a0a723902622a0a222a960a91b8152610145600b8201522061ffff198154169055602460405163424f535360e01b815261014560048201522061ffff1981541690556040516122ee81614ff1565b6000815260208101906000825261235062ffffff604083016000815261ffff806001606087019660008852602860405167141493d4d41150d560c21b815261014160088201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161237481614ff1565b69021e19e0c9bab240000081526020810190600182526123de62ffffff604083016103e8815261ffff8060016060870196600a885260266040516526a2a6a122a960d11b815261014160068201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161240281614ff1565b69043c33c1937564800000815260208101906002825261246d62ffffff604083016107d0815261ffff8060016060870196600a8852602760405166242aa9aa2622a960c91b815261014160078201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161249181614ff1565b69065a4da25d3016c00000815260208101906003825261250362ffffff60408301611388815261ffff8060016060870196600a8852602e6040516d29aa2922a2aa1029a7a62224a2a960911b8152610141600e8201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161252781614ff1565b690a968163f0a57b400000815260208101906005825261259362ffffff60408301612710815261ffff8060016060870196600a885260286040516722a72327a921a2a960c11b815261014160088201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b19161790556040516125b781614ff1565b69152d02c7e14af680000081526020810190600a825261262262ffffff60408301613a98815261ffff8060016060870196600a885260276040516627a32324a1a2a960c91b815261014160078201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161264681614ff1565b6934f086f3b33b6840000081526020810190601982526126b162ffffff60408301614e20815261ffff8060016060870196600a885260276040516621a0a82a20a4a760c91b815261014160078201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b19161790556040516126d581614ff1565b6969e10de76676d0800000815260208101906032825261274062ffffff60408301617530815261ffff8060016060870196600a885260276040516611d1539154905360ca1b815261014160078201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161276481614ff1565b69d3c21bcecceda100000081526020810190606482526127d362ffffff60408301619c40815261ffff8060016060870196600f8852602b6040516a23a0a723902622a0a222a960a91b8152610141600b8201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b19161790556040516127f781614ff1565b6a02116545850052128000008152602081019060fa825261286062ffffff6040830161c350815261ffff8060016060870196600f8852602460405163424f535360e01b815261014160048201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905561287e57005b61ff0019600054166000557f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498602060405160018152a1005b634e487b7160e01b600052604160045260246000fd5b909260206128f16001928460ff885116919060ff809160031b9316831b921b19161790565b94019101612073565b6101386000527ff79a63dcec80ed75c82f36161f17b9c2f407860160383a7be0a0ee7962c527ae805462ffffff16815561295b91601f0160051c017ff79a63dcec80ed75c82f36161f17b9c2f407860160383a7be0a0ee7962c527af6159b8565b82612061565b61ffff19166101011760005584611f5d565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b50303b158015611f475750600160ff821614611f47565b50600160ff821610611f40565b34610823576020366003190112610823576001600160a01b03612a14614f2f565b166000526101426020526040600020805490612a2f826150ef565b91612a3d604051938461505e565b80835260208301809260005260206000206000915b838310612ac057848660405191829160208301906020845251809152604083019060408160051b85010192916000905b828210612a9157505050500390f35b91936001919395506020612ab08192603f198a82030186528851614f5b565b9601920192018594939192612a82565b60036020600192612ad085615224565b815201920192019190612a52565b346108235760a0366003190112610823576004356001600160401b03811161082357612b0e9036906004016150d1565b612b16615106565b90612b1f6151a1565b6084359160ff831680930361082357612bad9161ffff80600162ffffff94612b45615cb8565b612b87602060405192612b5784614ff1565b6024358452858285019c168c52886040850198168852606084019a8b5281604051938285809451938492016157ce565b810161014181520301902090518155019651161661ffff19865416178555511683615c10565b51815465ff0000000000191660289190911b60ff60281b16179055005b3461082357600036600319011261082357602061013654604051908152f35b3461082357606036600319011261082357612c02614f0f565b612c0a614f1f565b906044359060ff82168092036108235760ff90612c25615cb8565b1691606483118015612d2b575b8015612d21575b610af55760ff9060405193612c4d8561500c565b845216602083015260408201526101385460036101385580600310612cba575b50610138600052602060002060009160005b60038110612c8c57505055005b90926020612cb16001928460ff885116919060ff809160031b9316831b921b19161790565b94019101612c7f565b6101386000527ff79a63dcec80ed75c82f36161f17b9c2f407860160383a7be0a0ee7962c527ae805462ffffff168155612d1b91601f0160051c017ff79a63dcec80ed75c82f36161f17b9c2f407860160383a7be0a0ee7962c527af6159b8565b81612c6d565b5060648211612c39565b50606460ff821611612c32565b3461082357602036600319011261082357610019612d54614f2f565b612d5c615cb8565b615c2c565b34610823576060366003190112610823576004356024359061ffff8216809203610823576044359062ffffff8216809203610823576100199261ffff91612da6615cb8565b8360408051612db48161500c565b838152846020820152015261013a551661ffff1961013b54161761013b5564ffffff000061013b549160101b169064ffffff000019161761013b55565b3461082357600036600319011261082357602060ff6101395416604051908152f35b3461082357604036600319011261082357612e2c614f2f565b60243590612e38615cb8565b8115610af5576040516370a0823160e01b81523060048201526001600160a01b039190911690602081602481855afa90811561083057600091612edc575b508211610ae45760405163a9059cbb60e01b81523360048201526024810192909252602090829060449082906000905af190811561083057600091612ebd575015610ad357005b612ed6915060203d60201161106357611055818361505e565b81610acb565b90506020813d602011612f06575b81612ef76020938361505e565b81010312610823575183612e76565b3d9150612eea565b3461082357602036600319011261082357612f27614f2f565b612f2f6157a3565b5060018060a01b031660005261014060205260a0604060002063ffffffff60405191612f5a83615027565b818154938481528160018401541692602082019384528260036002830154926040850193845201549481608060608601958289168752019660201c168652604051978852511660208701525160408601525116606084015251166080820152f35b34610823576000366003190112610823576097546040516001600160a01b039091168152602090f35b3461082357604036600319011261082357600435602435613003615d10565b61300b615d54565b61012d546040516370a0823160e01b81523360048201526001600160a01b0390911690602081602481855afa908115610830576000916131f6575b5082116117fa57604051636eb1769f60e11b81526020818061306c303360048401615633565b0381855afa908115610830576000916131c4575b50821161102a57602060ff61013954166044604051809481936367c05ed960e01b835288600484015260248301525afa90811561083057600091613192575b508110610af55760206131276000923384526101468352604084206130e5868254615687565b90556130f48161013354615687565b6101335561012d546040516323b872dd60e01b81529485936001600160a01b039092169284928391303360048501615665565b03925af190811561083057600091613173575b5015610ad3576040519081527f1127e24bcbd5e76f9e15cc9ba6972b781e0b33e58347337c0a5e994d4868342860203392a2600160fb55005b61318c915060203d60201161106357611055818361505e565b8261313a565b90506020813d6020116131bc575b816131ad6020938361505e565b810103126108235751836130bf565b3d91506131a0565b90506020813d6020116131ee575b816131df6020938361505e565b81010312610823575184613080565b3d91506131d2565b90506020813d602011613220575b816132116020938361505e565b81010312610823575184613046565b3d9150613204565b3461082357600036600319011261082357613241615d10565b613249615d54565b3360005261014460205260246040600020613266610131546151b3565b50610130546040516344d7b31560e11b81523360048201529260009184919082906001600160a01b03165afa9182156108305760009182918394613634575b508215808061362c575b80613623575b611de157478411610ae45761012e546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa908115610830576000916135f1575b508311610ae45761330e848354615687565b82556001820161331f848254615687565b905560038201805463ffffffff19164263ffffffff16179055156135b9575b8161352d575b8351613391575b50907fd48017f8fc60ac35ced01680518c1b007f6d5fcf6867aef68546ad421b29c9a59160405191825260208201526060604082015280610d9a33946060830190614fbd565b91929060005b6101315480821015613500576133ac826155fe565b905460039190911b1c6001600160a01b03166133cc575b50600101613397565b6133d5826155fe565b60018060a01b0391549060031b1c1690600286019081549081106134a6575b506134696000926020926134276134168761340f818c615991565b519361561b565b91909283549260031b92831c615687565b82548719831b1916911b17905561343e8588615991565b5160405163a9059cbb60e01b8152336004820152602481019190915293849283919082906044820190565b03925af190811561083057600091613488575b5015610ad357856133c3565b6134a0915060203d811161106357611055818361505e565b8661347c565b96919392949590965b610131548110156134ef57875490600160401b8210156128b6576134da8260018094018b558a61561b565b8154906000199060031b1b19169055016134af565b5090959094939192906134696133f4565b509193925090507fd48017f8fc60ac35ced01680518c1b007f6d5fcf6867aef68546ad421b29c9a561334b565b61353a8261013654615687565b6101365561012e5460405163a9059cbb60e01b81523360048201526024810184905290602090829060449082906000906001600160a01b03165af19081156108305760009161359a575b5061334457632185bbe960e01b60005260046000fd5b6135b3915060203d60201161106357611055818361505e565b85613584565b6135c68361013554615687565b61013555600080808086335af16135db615be0565b5061333e57632185bbe960e01b60005260046000fd5b90506020813d60201161361b575b8161360c6020938361505e565b810103126108235751866132fc565b3d91506135ff565b508451156132b5565b5082156132af565b9150925061364b913d8091833e61159a818361505e565b92846132a5565b346108235761366036615117565b613668615d10565b613670615d54565b61ffff8151163360005261014260205261ffff60406000205416913360005261013f602052604060002054918015610af55733600052610142602052604060002060001985019061ffff8211610942576136cd91610e97916151f2565b9361ffff855116156117fa57613979575b92602081018051916000955b845187101561380757600095865b85518110156137fb5761ffff61370e8a89615991565b511661ffff61371d8389615991565b51161461372c576001016136f8565b90939297919496506001908751838301908184116109425761375d6137576137669361ffff936151e5565b8b615991565b51169189615991565b5261012f546001600160a01b031661ffff6137818489615991565b511690803b1561082357604051632142170760e11b815230600482015233602482015261ffff9290921660448301526000908290606490829084905af18015610830576137ea575b505b156137dd5760010195909194926136ea565b610bd661ffff9186615991565b60006137f59161505e565b886137c9565b509291969093956137cb565b9492613819610ed782518751906151e5565b908151613934575b508561ffff835116039261ffff84116109425761ffff61385f941683525263ffffffff421660408201523360005261014260205260406000206159cf565b336000526101426020526040600020546138a8575b50610d9a7f8062d6c146a1b0936b5b8dd244693cf579fe2b5af516678c1f4f8e8f347d876291604051918291339583615b97565b60006138b791610db333615560565b03915afa9182156108305761390860207f8062d6c146a1b0936b5b8dd244693cf579fe2b5af516678c1f4f8e8f347d876294610d9a94600091611ce5575081604051938285809451938492016157ce565b810161014581520301902061ffff61392281835416615b84565b1661ffff198254161790559150613874565b959260009592959491945b855181101561396b578061ffff6139586001938b615991565b51166139648289615991565b520161393f565b509295509293909386613821565b610130548451604051637dd46cc160e01b81526004810186905261ffff909116602482015290600090829060449082906001600160a01b03165afa908115610830576139dd91602091600091611ce5575081604051938285809451938492016157ce565b810161014581520301902061ffff6139f7818354166158d6565b1661ffff198254161790556136de565b346108235760203660031901126108235760043561013854811015610823576000610138548210156107e55760209160f8838361013860ff9552208260051c01549160031b161c16604051908152f35b3461082357600036600319011261082357604051806020610131549283815201809261013160005260206000209060005b818110613aea5750505081613a9e91038261505e565b6040519182916020830190602084525180915260408301919060005b818110613ac8575050500390f35b82516001600160a01b0316845285945060209384019390920191600101613aba565b82546001600160a01b0316845260209093019260019283019201613a88565b3461082357600036600319011261082357613b22615cb8565b609780546001600160a01b031981169091556000906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b3461082357600036600319011261082357602063ffffffff6101375416604051908152f35b3461082357600036600319011261082357602062ffffff6101395460081c16604051908152f35b346108235760003660031901126108235761013d54613bd0816150ef565b90613bde604051928361505e565b80825261013d60009081526020830191907f311617e6f2abe00ca92b0da56c014828817049e78441cf034e4dd4feba529625835b838310613d2657848660405191829160208301906020845251809152604083019060408160051b85010192916000905b828210613c5157505050500390f35b919360019193955060208091603f1989820301855287519063ffffffff825116815282820151838201526040820151604082015261018061ffff81613ca760608601516101a060608701526101a0860190614fbd565b948260808201511660808601528260a08201511660a08601528260c08201511660c08601528260e08201511660e086015282610100820151166101008601528261012082015116610120860152826101408201511661014086015282610160820151166101608601520151169101529601920192018594939192613c42565b60056020600192613d36856158e7565b815201920192019190613c12565b3461082357600036600319011261082357613d5d615d10565b613d65615d54565b3360005261013f602052604060002060018060a01b03610130541660405191638ca1a34560e01b8352336004840152602083602481855afa92831561083057600093614066575b506040516344d7b31560e11b815233600482015291600083602481845afa801561083057600093600091614044575b5082549384156117fa5761012d546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa90811561083057600091614012575b508511610ae4576002840195865463ffffffff42161061400157806115aa57508015801590613ff8575b61156357505033600052610142602052604060002054613f41575b508054600080835560018301805464ffffffffff19169055909355600301805463ffffffff191690555061013254613e9f9082906151e5565b6101325561012d5460405163a9059cbb60e01b81523360048201526024810183905290602090829060449082906000906001600160a01b03165af190811561083057600091613f22575b5015610ad3576040519081527f5c879a554f3e9522fb42e4979579ce936c485c1092dc49d9cc16869dc458620160203392a2600160fb55005b613f3b915060203d60201161106357611055818361505e565b82613ee9565b613f849260009161ffff613f5433615560565b51604051637dd46cc160e01b815260048101949094521661ffff1660248301529093849190829081906044820190565b03915afa8015610830576020613fb291600394600091613fdd575081604051938285809451938492016157ce565b810161014581520301902061ffff613fcc818354166158d6565b1661ffff1982541617905583613e66565b613ff291503d806000833e610e5e818361505e565b86610e0a565b50811515613e4b565b6349793d0560e01b60005260046000fd5b90506020813d60201161403c575b8161402d6020938361505e565b81010312610823575187613e21565b3d9150614020565b905061405c9193503d806000833e61159a818361505e565b5092909285613ddb565b90926020823d602011614092575b816140816020938361505e565b81010312610c255750519183613dac565b3d9150614074565b3461082357600036600319011261082357602060ff60c954166040519015158152f35b34610823576000366003190112610823577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163003614116576020604051600080516020615f3f8339815191528152f35b60405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c6044820152771b1959081d1a1c9bdd59da0819195b1959d85d1958d85b1b60421b6064820152608490fd5b34610823576020366003190112610823576001600160a01b0361419d614f2f565b166000526101466020526020604060002054604051908152f35b6040366003190112610823576141cb614f2f565b6024356001600160401b0381116108235736602382011215610823576141fb90369060248160040135910161509a565b906142547f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316614235308214156156e1565b600080516020615f3f833981519152546001600160a01b031614615742565b61425c615cb8565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615614290576100199150615e53565b6040516352d1902d60e01b81526001600160a01b03821690602081600481855afa60009181614491575b5061431b5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608490fd5b600080516020615f3f8339815191520361443a5761433882615e53565b604051907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2825115801590614432575b61437257005b813b156143e157506000828192602061001995519201905af4614393615be0565b604051916143a260608461505e565b602783527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c6020840152660819985a5b195960ca1b6040840152615ee4565b62461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608490fd5b50600161436c565b60405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608490fd5b9091506020813d6020116144bd575b816144ad6020938361505e565b81010312610823575190856142ba565b3d91506144a0565b34610823576020366003190112610823576144de614f2f565b6144e6615cb8565b61013080546001600160a01b0319166001600160a01b0392909216919091179055005b34610823576020366003190112610823576004356001600160401b0381116108235761ffff6145426020610a1c819436906004016150d1565b81016101458152030190205416604051908152f35b3461082357602036600319011261082357614570614f2f565b6145786157a3565b5060018060a01b031660005261013f60205260a0604060002063ffffffff6040516145a281615027565b82549283825260ff60018201548460208501818316815283604087019360201c168352608082600360028801549760608a019889520154169601958652604051978852511660208701525116604085015251606084015251166080820152f35b346108235760003660031901126108235761013c546040516001600160a01b039091168152602090f35b3461082357602036600319011261082357614645614f2f565b61467e7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316614235308214156156e1565b614686615cb8565b602090604051614696838261505e565b6000815282810190601f1984013683377f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156146dc5750506100199150615e53565b6040516352d1902d60e01b81526001600160a01b038416908581600481855afa600091816148d8575b506147665760405162461bcd60e51b815260048101879052602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608490fd5b600080516020615f3f833981519152036148815761478384615e53565b604051907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2815115801590614879575b6147bd57005b833b1561482857506100199392600092839251915af46147db615be0565b907f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c6040519361480c60608661505e565b60278552840152660819985a5b195960ca1b6040840152615ee4565b62461bcd60e51b815260048101859052602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608490fd5b5060006147b7565b60405162461bcd60e51b815260048101869052602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608490fd5b9091508681813d8311614900575b6148f0818361505e565b8101031261082357519087614705565b503d6148e6565b34610823576020366003190112610823576149866020614925614f2f565b60018060a01b03811660005261013f825261ffff61494860406000205492615560565b51610130546040516340b5f39d60e11b81526004810194909452911661ffff166024830152909283916001600160a01b031690829081906044820190565b03915afa8015610830576000906149a3575b602090604051908152f35b506020813d6020116149ce575b816149bd6020938361505e565b810103126108235760209051614998565b3d91506149b0565b3461082357600036600319011261082357606061013a5462ffffff61013b5460405192835261ffff8116602084015260101c166040820152f35b3461082357602036600319011261082357614a29614f2f565b600060408051614a388161500c565b828152826020820152015260018060a01b03166000526101436020526060604060002063ffffffff60405191614a6d8361500c565b548160ff82161515938481528160406020830192828660081c168452019360281c1683526040519485525116602084015251166040820152f35b3461082357602036600319011261082357614ac0614f2f565b60006060604051614ad081614ff1565b828152826020820152816040820152015260018060a01b03166000526101446020526040600020604051614b0381614ff1565b815481526001820154916020820192835263ffffffff614b66816003614b2b60028601615694565b9460408701958652015416926060850193845260405195869560208752516020870152516040860152516080606086015260a0850190614fbd565b91511660808301520390f35b3461082357600036600319011261082357602061013554604051908152f35b3461082357602036600319011261082357600435614bad615cb8565b8015610af55761012d546040516370a0823160e01b81523360048201526001600160a01b0390911690602081602481855afa90811561083057600091614cd0575b5082116117fa57604051636eb1769f60e11b815260208180614c14303360048401615633565b0381855afa90811561083057600091614c9e575b50821161102a57602060405180926323b872dd60e01b825281600081614c5388303360048501615665565b03925af190811561083057600091614c7f575b5015610ad357614c799061013354615687565b61013355005b614c98915060203d60201161106357611055818361505e565b82614c66565b90506020813d602011614cc8575b81614cb96020938361505e565b81010312610823575183614c28565b3d9150614cac565b90506020813d602011614cfa575b81614ceb6020938361505e565b81010312610823575183614bee565b3d9150614cde565b3461082357602036600319011261082357614d1b614f2f565b614d23615cb8565b610131546001600160a01b039091169060005b818110614de957506040516318160ddd60e01b8152602081600481865afa90811561083057600091614db7575b5015614da657600160401b8110156128b657806001614d869201610131556155fe565b81546001600160a01b0360039290921b91821b191692901b919091179055005b634043ee0160e01b60005260046000fd5b90506020813d602011614de1575b81614dd26020938361505e565b81010312610823575183614d63565b3d9150614dc5565b82614df3826155fe565b905460039190911b1c6001600160a01b031614614e1257600101614d36565b6314bb0be160e11b60005260046000fd5b3461082357602036600319011261082357614e5b614e47614e42614f2f565b615560565b604051918291602083526020830190614f5b565b0390f35b3461082357608036600319011261082357614e78614f2f565b50614e81614f45565b506064356001600160401b03811161082357366023820112156108235780600401356001600160401b038111610823573691016024011161082357604051630a85bd0160e11b8152602090f35b3461082357602036600319011261082357614ee7614f0f565b614eef615cb8565b61013c805460ff60a01b191660a09290921b60ff60a01b16919091179055005b6004359060ff8216820361082357565b6024359060ff8216820361082357565b600435906001600160a01b038216820361082357565b602435906001600160a01b038216820361082357565b90606081019161ffff815116825260208101519260606020840152835180915260206080840194019060005b818110614fa35750505063ffffffff6040809201511691015290565b825161ffff16865260209586019590920191600101614f87565b906020808351928381520192019060005b818110614fdb5750505090565b8251845260209384019390920191600101614fce565b608081019081106001600160401b038211176128b657604052565b606081019081106001600160401b038211176128b657604052565b60a081019081106001600160401b038211176128b657604052565b6101a081019081106001600160401b038211176128b657604052565b90601f801991011681019081106001600160401b038211176128b657604052565b6001600160401b0381116128b657601f01601f191660200190565b9291926150a68261507f565b916150b4604051938461505e565b829481845281830111610823578281602093846000960137010152565b9080601f83011215610823578160206150ec9335910161509a565b90565b6001600160401b0381116128b65760051b60200190565b6044359061ffff8216820361082357565b602060031982011261082357600435906001600160401b03821161082357806023830112156108235781600401359061514f826150ef565b9261515d604051948561505e565b8284526024602085019360051b82010191821161082357602401915b8183106151865750505090565b823561ffff8116810361082357815260209283019201615179565b6064359062ffffff8216820361082357565b906151bd826150ef565b6151ca604051918261505e565b82815280926151db601f19916150ef565b0190602036910137565b9190820391821161094257565b805482101561520e576000526003602060002091020190600090565b634e487b7160e01b600052603260045260246000fd5b906040516152318161500c565b809261ffff8154168252600181016040519081602082549182815201916000526020600020906000915b81600f84011061547e57846002946040979463ffffffff9794615300945491818110615469575b818110615451575b81811061543a575b818110615422575b81811061540b575b8181106153f3575b8181106153db575b8181106153c3575b8181106153ab575b818110615393575b81811061537b575b818110615363575b81811061534b575b818110615333575b81811061531b575b1061530d575b50038261505e565b6020860152015416910152565b60f01c8152602001386152f8565b92602060019161ffff8560e01c1681520193016152f2565b92602060019161ffff8560d01c1681520193016152ea565b92602060019161ffff8560c01c1681520193016152e2565b92602060019161ffff8560b01c1681520193016152da565b92602060019161ffff8560a01c1681520193016152d2565b92602060019161ffff8560901c1681520193016152ca565b92602060019161ffff8560801c1681520193016152c2565b92602060019161ffff8560701c1681520193016152ba565b92602060019161ffff8560601c1681520193016152b2565b92602060019161ffff8560501c1681520193016152aa565b92602060019161ffff858e1c1681520193016152a2565b92602060019161ffff8560301c16815201930161529a565b92602060019161ffff85831c168152019301615292565b92602060019161ffff8560101c16815201930161528a565b92602060019161ffff85168152019301615282565b926001610200601092865461ffff8116825261ffff81861c16602083015261ffff8160201c16604083015261ffff8160301c16606083015261ffff8160401c16608083015261ffff8160501c1660a083015261ffff8160601c1660c083015261ffff8160701c1660e083015261ffff8160801c1661010083015261ffff8160901c1661012083015261ffff8160a01c1661014083015261ffff8160b01c1661016083015261ffff8160c01c1661018083015261ffff8160d01c166101a083015261ffff8160e01c166101c083015260f01c6101e082015201940192019161525b565b60405161556c8161500c565b6000815260606020820152600060408201525060018060a01b031680600052610142602052604060002054156155c7576000908152610142602052604090208054600019810191908211610942576150ec91610e97916151f2565b5060206040516155d7828261505e565b600081526000368137604051916155ed8361500c565b600083528201526000604082015290565b6101315481101561520e5761013160005260206000200190600090565b805482101561520e5760005260206000200190600090565b6001600160a01b0391821681529116602082015260400190565b90816020910312610823575180151581036108235790565b6001600160a01b03918216815291166020820152604081019190915260600190565b9190820180921161094257565b906040519182815491828252602082019060005260206000209260005b8181106156c85750506156c69250038361505e565b565b84548352600194850194879450602090930192016156b1565b156156e857565b60405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201526b19195b1959d85d1958d85b1b60a21b6064820152608490fd5b1561574957565b60405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201526b6163746976652070726f787960a01b6064820152608490fd5b604051906157b082615027565b60006080838281528260208201528260408201528260608201520152565b60005b8381106157e15750506000910152565b81810151838201526020016157d1565b9091606082840312610823578151926020830151926040810151906001600160401b03821161082357019080601f83011215610823578151615832816150ef565b92615840604051948561505e565b81845260208085019260051b82010192831161082357602001905b8282106158685750505090565b815181526020918201910161585b565b602081830312610823578051906001600160401b038211610823570181601f820112156108235780516158aa8161507f565b926158b8604051948561505e565b81845260208284010111610823576150ec91602080850191016157ce565b61ffff168015610942576000190190565b906040516158f481615042565b61018061ffff6004839563ffffffff8154168552600181015460208601526002810154604086015261592860038201615694565b606086015201548181166080850152818160101c1660a0850152818160201c1660c0850152818160301c1660e0850152818160401c16610100850152818160501c16610120850152818160601c16610140850152818160701c1661016085015260801c16910152565b805182101561520e5760209160051b010190565b8181029291811591840414171561094257565b8181106159c3575050565b600081556001016159b8565b8054600160401b8110156128b6576159ec916001820181556151f2565b919091615b6e5761ffff808251161661ffff198354161782556001820160208201518051906001600160401b0382116128b657600160401b82116128b6576020908354838555808410615b1c575b50019160005260206000208160041c9160005b838110615adb5750600f198116900380615a86575b50505050600263ffffffff604081930151169201911663ffffffff19825416179055565b9260009360005b818110615aa8575050500155600263ffffffff604081615a62565b9091946020615ad160019261ffff8951169085851b61ffff809160031b9316831b921b19161790565b9601929101615a8d565b6000805b60108110615af4575083820155600101615a4d565b865190969160019160209161ffff60048b901b81811b199092169216901b1792019601615adf565b615b4c908560005283600020600f80870160041c820192601e8860011b1680615b52575b500160041c01906159b8565b38615a3a565b600019850190815490600019908a0360031b1c16905538615b40565b634e487b7160e01b600052600060045260246000fd5b61ffff1661ffff81146109425760010190565b606060209161ffff604082019416815260408382015284518094520192019060005b818110615bc65750505090565b825161ffff16845260209384019390920191600101615bb9565b3d15615c0b573d90615bf18261507f565b91615bff604051938461505e565b82523d6000602084013e565b606090565b9064ffffff000082549160101b169064ffffff00001916179055565b60005b61013154811015615c8657615c43816155fe565b905460039190911b1c6001600160a01b0390811690831614615c6757600101615c2f565b615c7191506155fe565b81549060018060a01b039060031b1b19169055565b63d997d28d60e01b60005260046000fd5b61013d5481101561520e5761013d6000526005602060002091020190600090565b6097546001600160a01b03163303615ccc57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b60ff60c95416615d1c57565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b600260fb5414615d6557600260fb55565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b609780546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b15615dfa57565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b803b15615e8957600080516020615f3f83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b60405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b90919015615ef0575090565b815115615f005750805190602001fd5b6044604051809262461bcd60e51b825260206004830152615f3081518092816024860152602086860191016157ce565b601f01601f19168101030190fdfe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbca2646970667358221220b349fe187343da9ab531cde4c3e451c7106369fda86a1d2b7911aab5156b1aef64736f6c634300081a0033

Deployed Bytecode

0x6080604052600436101561001b575b361561001957600080fd5b005b60003560e01c8063067262de14614ece578063150b7a0214614e5f578063163f2c2214614e235780631703a44d14614d025780631e5cd51a14614b9157806322f8a23314614b7257806325458b3114614aa75780632e7b263514614a105780632fbd1ea2146149d65780633475122b146149075780633659cfe61461462c5780633e3d63fa14614602578063487ae0d714614557578063491763351461450957806349571a5e146144c55780634f1ef286146141b75780634f238b791461417c57806352d1902d146140bd5780635c975abb1461409a5780635d8f767414613d4457806366cb402914613bb257806367e1947214613b8b5780636dfa125c14613b66578063715018a614613b0957806372038abb14613a5757806376caca1a14613a07578063850c5598146136525780638565d240146132285780638904476714612fe45780638da5cb5b14612fbb5780638dceeeec14612f0e578063a1db978214612e13578063a263581c14612df1578063a2d56a3c14612d61578063a7d742ba14612d38578063abd7334114612be9578063ada8b78614612bca578063af399e3614612ade578063b980d799146129f3578063c0c53b8b14611ef4578063d47cc5f714611e4b578063da17349e14611e26578063dcd048601461191a578063e1821cbc14611867578063e18b89851461118d578063e628c8771461116e578063e67cc38e146110a8578063e94cb10714611089578063ed35918f1461106a578063ed97a02014610b06578063f14210a614610a91578063f164c0d5146109e5578063f2fde38b14610958578063f6a684af1461083c5763fa43bf900361000e573461082357600036600319011261082357610296615cb8565b61012e546040516370a0823160e01b81523060048201524791602090829060249082906001600160a01b03165afa908115610830576000916107f9575b50606090600061013854156107e5576102fe60208261013860649452209460ff6000965416906159a5565b049161013854600110156107d1576101388452606461032b602086209360ff6001955460081c16906159a5565b0490610131548061069e575b5061ffff60266040516526a2a6a122a960d11b815261014560068201522054169361ffff602760405166242aa9aa2622a960c91b815261014560078201522054169361ffff602e6040516d29aa2922a2aa1029a7a62224a2a960911b8152610145600e8201522054169161ffff60286040516722a72327a921a2a960c11b815261014560088201522054169061ffff60276040516627a32324a1a2a960c91b815261014560078201522054169661ffff60276040516621a0a82a20a4a760c91b815261014560078201522054169161ffff60276040516611d1539154905360ca1b815261014560078201522054169461ffff602b6040516a23a0a723902622a0a222a960a91b8152610145600b8201522054169761ffff602460405163424f535360e01b81526101456004820152205416996040519361047685615042565b4263ffffffff168552602085019081526040850191825260608501928352608085019d8e5260a0850195865260c08501998a5260e0850197885261010085019c8d526101208501968752610140850198895261016085019a8b5261018085019b8c5261013d54600160401b811015610689578060016104f9920161013d55615c97565b9590956106745751855463ffffffff191663ffffffff919091161785555160018501555160028401555180519060038401906001600160401b03831161066057600160401b8311610660579060208f928254858455808610610646575b500191528d60208120905b83811061063357505050505061ffff60048192019a51161661ffff198a54161789555167ffff00000000000065ffff000000008a54965160201b16935160301b169761ffff60401b905160401b169161ffff60501b905160501b169361ffff60601b905160601b169561ffff60701b905160701b169661ffff60801b905160801b169761ffff60801b199561ffff60701b199461ffff60601b199361ffff60501b199263ffff000061ffff60401b199260101b169067ffffffffffff0000191617161716171617161716171717905580f35b8490602084519401938184015501610561565b83855282852061065a9181019087016159b8565b38610556565b634e487b7160e01b8f52604160045260248ffd5b50634e487b7160e01b8f5260048f905260248ffd5b50634e487b7160e01b8f52604160045260248ffd5b90506106a9816151b3565b9083865b8281106106bb575050610337565b6106c4816155fe565b905460039190911b1c6001600160a01b03166106e3575b0184906106ad565b9050602460206106f2836155fe565b90546040516370a0823160e01b81523060048201529384929091839160031b1c6001600160a01b03165afa9081156107c6578891610791575b506107368285615991565b526107418184615991565b51610138546002101561077d5790606461076c87936101388b5260ff60208c205460101c16906159a5565b046107778286615991565b526106db565b634e487b7160e01b88526032600452602488fd5b90506020813d82116107be575b816107ab6020938361505e565b810103126107ba57513861072b565b8780fd5b3d915061079e565b6040513d8a823e3d90fd5b634e487b7160e01b84526032600452602484fd5b634e487b7160e01b81526032600452602490fd5b90506020813d602011610828575b816108146020938361505e565b810103126108235751386102d3565b600080fd5b3d9150610807565b6040513d6000823e3d90fd5b346108235760003660031901126108235761013d5460001981019081116109425761087161086b602092615c97565b506158e7565b63ffffffff815116908281015160408201519160608101519261ffff6080830151169361ffff60a08401511661ffff60c08501511661ffff60e0860151169061ffff610100870151169261090b61ffff610120890151169561ffff6101408a0151169761ffff610180816101608d0151169b0151169a6040519e8f9e8f908152015260408d01526101a060608d01526101a08c0190614fbd565b9860808b015260a08a015260c089015260e08801526101008701526101208601526101408501526101608401526101808301520390f35b634e487b7160e01b600052601160045260246000fd5b3461082357602036600319011261082357610971614f2f565b610979615cb8565b6001600160a01b038116156109915761001990615daa565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b34610823576020366003190112610823576004356001600160401b03811161082357610a2f6020610a1c60809336906004016150d1565b81604051938285809451938492016157ce565b81016101418152030190206060604051610a4881614ff1565b600183549384835201549061ffff82169081602082015260ff62ffffff8460101c169384604084015260281c169384910152604051938452602084015260408301526060820152f35b3461082357602036600319011261082357600435610aad615cb8565b8015610af557478111610ae457600080808093335af1610acb615be0565b5015610ad357005b632185bbe960e01b60005260046000fd5b63280bb89b60e11b60005260046000fd5b632eb4702560e21b60005260046000fd5b3461082357610b1436615117565b610b1c615d10565b610b24615d54565b61ffff815116336000526101426020526040600020543360005261013f602052604060002054928215610af55761012f546001600160a01b0316939260005b61ffff811682811015610c345761ffff610b7d8286615991565b516040516331a9108f60e11b8152911660048201526020816024818b5afa90811561083057600091610bec575b50336001600160a01b0390911603610bc9575060010161ffff16610b63565b610bd661ffff9185615991565b5116635b7f003760e11b60005260045260246000fd5b6020813d8211610c2c575b81610c046020938361505e565b81010312610c285751906001600160a01b0382168203610c25575088610baa565b80fd5b5080fd5b3d9150610bf7565b505060405163e985e9c560e01b815284908490602081898180610c5b303360048401615633565b03915afa9081156108305760009161103b575b501561102a5780158015610f6d575b15610e6c5750610cbb604051610c928161500c565b83815284602082015263ffffffff421660408201523360005261014260205260406000206159cf565b33600052610142602052604060002054610da4575b5060005b61ffff81169082821015610d675761012f546001600160a01b03169161ffff90610cfe9086615991565b511691803b1561082357604051632142170760e11b815233600482015230602482015261ffff9390931660448401526000908390606490829084905af19081156108305761ffff92600192610d56575b500116610cd4565b6000610d619161505e565b85610d4e565b60405133907f0ec1e973d17a791ac1d35b376dcaa8acdc59097156eadb6860e2d78bab0b3dfb9080610d9a888883615b97565b0390a2600160fb55005b6000610df091610db333615560565b610130549051604051637dd46cc160e01b8152600481019390935261ffff166024830152909283916001600160a01b031690829081906044820190565b03915afa90811561083057610e1e91602091600091610e49575b5081604051938285809451938492016157ce565b810161014581520301902061ffff610e3881835416615b84565b1661ffff1982541617905582610cd0565b610e6691503d806000833e610e5e818361505e565b810190615878565b85610e0a565b929092336000526101426020526040600020600019820191821161094257610e9d91610e97916151f2565b50615224565b908261ffff8351160161ffff81116109425761ffff16825263ffffffff421660408301526020820192835194610edc610ed7838851615687565b6151b3565b9360005b8751811015610f0c578061ffff610ef96001938b615991565b5116610f058289615991565b5201610ee0565b509295949093919460005b868110610f4057505090610f3b9291523360005261014260205260406000206159cf565b610cbb565b8061ffff610f506001938b615991565b5116610f66610f60838651615687565b87615991565b5201610f17565b610fb86000610f7b33615560565b610130549051604051637dd46cc160e01b81526004810188905261ffff90911660248201529283916001600160a01b031690829081906044820190565b03915afa90811561083057610fe59160209160009161100f575081604051938285809451938492016157ce565b810161014581520301902061ffff610fff818354166158d6565b1661ffff19825416179055610c7d565b61102491503d806000833e610e5e818361505e565b88610e0a565b6323403ae760e11b60005260046000fd5b61105d915060203d602011611063575b611055818361505e565b81019061564d565b85610c6e565b503d61104b565b3461082357600036600319011261082357602061013254604051908152f35b3461082357600036600319011261082357602061013454604051908152f35b34610823576080366003190112610823576110c1614f1f565b6110c9615106565b906110d26151a1565b6110da615cb8565b610137549263ffffffff84169363ffffffff85146109425763ffffffff1916600194850163ffffffff1690811761013755600090815261013e602052604090206004358155909301805469ffffffffffffffffffff191660ff939093169290921760089390931b62ffff00169290921760189290921b65ffffff00000016919091174260301b63ffffffff60301b16179055005b3461082357600036600319011261082357602061013354604051908152f35b6040366003190112610823576004356111a4614f1f565b906111ad615d10565b6111b5615d54565b63ffffffff610137541660005261013e6020526040600020604051926111da84615027565b6001825492838652015491602085019060ff8416825263ffffffff604087019461ffff8160081c16865262ffffff8160181c16606089015260301c166080870152841590811561185d575b50610af5575160ff828116939116831090811561184e575b5061183d5761012d546040516370a0823160e01b81523360048201526001600160a01b0390911690602081602481855afa9081156108305760009161180b575b5084116117fa5760206040518092636eb1769f60e11b825281806112a5303360048401615633565b03915afa908115610830576000916117c8575b50831161102a573360005261013f6020526040600020933360005261014260205260406000205415159283611709575b8554156115f057508454906112fd8583615687565b905110610af55761013054604051638ca1a34560e01b81523360048201526001600160a01b0390911690602081602481855afa908115610830576000916115be575b50806115aa57506000602491604051928380926344d7b31560e11b82523360048301525afa90811561083057600090600092611583575b50801580159061157a575b6115635750508361139191615687565b845560018401805463ffffffff19164263ffffffff1617908190556228206f602082901c60ff168181029181159183041417156109425763ffffffff6113d79216615687565b60028501556101375460038501805463ffffffff191663ffffffff9290921691909117905561012d546040516323b872dd60e01b81529060209082906001600160a01b03168160008161142f8a303360048501615665565b03925af190811561083057600091611544575b5015610ad3576040805184815260ff92909216602083015233917f5edc2559845a9a5b7f90429212d6be99f0394809a7b970fbc043c4ae37424e8c9190a25b61149e575b6114939061013254615687565b61013255600160fb55005b60006114eb926114ad33615560565b6101305491549051604051637dd46cc160e01b8152600481019290925261ffff1660248201529384916001600160a01b031690829081906044820190565b03915afa801561083057602061151a9161149394600091610e49575081604051938285809451938492016157ce565b810161014581520301902061ffff61153481835416615b84565b1661ffff19825416179055611486565b61155d915060203d60201161106357611055818361505e565b85611442565b634aa25a9d60e11b60005260045260245260446000fd5b50811515611381565b90506115a291503d806000833e61159a818361505e565b8101906157f1565b509087611376565b632f320e8f60e21b60005260045260246000fd5b906020823d6020116115e8575b816115d86020938361505e565b81010312610c255750518761133f565b3d91506115cb565b84865560018601805464ffffffffff19164263ffffffff16908117602086901b64ff00000000161790915591506228206f80820291801590830490911417156109425761163c91615687565b60028501556101375460038501805463ffffffff191663ffffffff9290921691909117905561012d546040516323b872dd60e01b81529060209082906001600160a01b0316816000816116948a303360048501615665565b03925af1908115610830576000916116ea575b5015610ad3576040805184815260ff92909216602083015233917ff55a761e85d1956c857a72e717bf2f52dcded09af3176bc37dad5290c1b82eeb9190a2611481565b611703915060203d60201161106357611055818361505e565b856116a7565b611756600061171733615560565b6101305489549151604051637dd46cc160e01b8152600481019390935261ffff166024830152909283916001600160a01b031690829081906044820190565b03915afa90811561083057611783916020916000916117ad575081604051938285809451938492016157ce565b810161014581520301902061ffff61179d818354166158d6565b1661ffff198254161790556112e8565b6117c291503d806000833e610e5e818361505e565b89610e0a565b90506020813d6020116117f2575b816117e36020938361505e565b810103126108235751856112b8565b3d91506117d6565b630233bbe560e61b60005260046000fd5b90506020813d602011611835575b816118266020938361505e565b8101031261082357518661127d565b3d9150611819565b6305ea81b560e11b60005260046000fd5b61ffff9150511682118561123d565b9050841186611225565b346108235760203660031901126108235760043563ffffffff8116809103610823576118916157a3565b5060005261013e60205260a0604060002063ffffffff6040516118b381615027565b62ffffff600184549485845201549161ffff6020820160ff8516815260ff6040840191838760081c1683528760806060870196888a60181c168852019760301c16875260405198895251166020880152511660408601525116606084015251166080820152f35b3461082357602036600319011261082357611933614f0f565b61193b615d10565b611943615d54565b336000526101406020526040600020903360005261013f6020526040600020913360005261014360205260406000209260018060a01b0361013054169060405190638ca1a34560e01b8252336004830152602082602481865afa91821561083057600092611df2575b5081948215611de15760ff1660648111610af557610133548311610ae45780611b0c575b5050505081611a34575b50816119fb925460ff811680611a1b575b611a06575b505061013454615687565b61013455600160fb55005b68ffffffffffffffffff1916905582806119f0565b5063ffffffff8160281c1663ffffffff421610156119eb565b80611a428360019354615687565b815501805463ffffffff19164263ffffffff1617905561013354611a679082906151e5565b6101335561012d5460405163a9059cbb60e01b81523360048201526024810183905290602090829060449082906000906001600160a01b03165af190811561083057600091611aed575b5015610ad3576119fb916040518281527f27e57bc8b08a3f45f6d9bb3847d286bc94ae50ed60734163713e34521d51aa9e60203392a2916119da565b611b06915060203d60201161106357611055818361505e565b83611ab1565b90919294506040516344d7b31560e11b8152336004820152600081602481895afa90811561083057600090600092611dc2575b508015801590611db9575b6115635750503360005261014260205260406000205415159485611d00575b50611b76606491846159a5565b0491611b83825484615687565b63ffffffff610137541660005261013e60205260406000205410610af55782611bab916151e5565b9360028401611bbb848254615687565b905560038401805463ffffffff19164263ffffffff161790558154611be1908490615687565b8255611bf083610133546151e5565b61013355611c018361013254615687565b61013255611c40575b506040519081527fb6296e8aa12725250cdc0076d6ff23122ef1f56621eb33ea8c149ba206e1751460203392a2838080806119d0565b6000611c8d91611c4f33615560565b6101305491549051604051637dd46cc160e01b8152600481019290925261ffff1660248201529283916001600160a01b031690829081906044820190565b03915afa90811561083057611cba91602091600091611ce5575081604051938285809451938492016157ce565b810161014581520301902061ffff611cd481835416615b84565b1661ffff1982541617905584611c0a565b611cfa91503d806000833e610e5e818361505e565b87610e0a565b6000611d4091611d0f33615560565b85549051604051637dd46cc160e01b8152600481019290925261ffff16602482015292839190829081906044820190565b03915afa91821561083057611d726020606494611b7694600091611d9e575081604051938285809451938492016157ce565b810161014581520301902061ffff611d8c818354166158d6565b1661ffff198254161790559150611b69565b611db391503d806000833e610e5e818361505e565b8b610e0a565b50811515611b4a565b9050611dd991503d806000833e61159a818361505e565b509088611b3f565b63294bf2bb60e11b60005260046000fd5b90916020823d602011611e1e575b81611e0d6020938361505e565b81010312610c2557505190866119ac565b3d9150611e00565b3461082357600036600319011261082357602060ff61013c5460a01c16604051908152f35b3461082357602036600319011261082357611e64614f2f565b611e6c615cb8565b6001600160a01b031660008181526101436020526040902061013c80546001600160a01b031916909217909155805464ffffffffff191642600890811b64ffffffff0016919091176001178083556228206f911c63ffffffff1690810190811061094257815468ffffffff0000000000191660289190911b68ffffffff000000000016179055005b3461082357606036600319011261082357611f0d614f2f565b611f15614f45565b6044356001600160a01b0381169190829003610823576000549260ff8460081c1615938480956129e6575b80156129cf575b156129735760ff19811660011760005584612961575b50611f7860ff60005460081c16611f7381615df3565b615df3565b611f8133615daa565b611fc560ff60005460081c16611f9681615df3565b611f9f81615df3565b60ff1960c9541660c955611fb281615df3565b611fbb81615df3565b600160fb55615df3565b61012d80546001600160a01b03199081166001600160a01b039384161790915561012e805482169390921692909217905561012f8054909116919091179055610137805463ffffffff1916905560006101328190556101338190556101348190556101358190556101365560405161203c8161500c565b60058152600560208201526005604082015261013854600361013855806003106128fa575b50610138600052602060002060009160005b600381106128cc57505055610139805463ffffffff1916630186a00a1790556101375463ffffffff16600090815261013e602052604090206a02116545850052128000008155600101805469ffffffffffffffffffff19164260301b63ffffffff60301b16176401f40030011790556064604080516120f18161500c565b683635c9adc5dea000008082526001602083015291019190915261013a5561013b805464ffffffffff191662640001179055604080519081018181106001600160401b038211176128b65760199160209160405260008152015260018060a01b031961013c541661013c55601960a01b60ff60a01b1961013c54161761013c55602860405167141493d4d41150d560c21b815261014560088201522061ffff19815416905560266040516526a2a6a122a960d11b815261014560068201522061ffff198154169055602760405166242aa9aa2622a960c91b815261014560078201522061ffff198154169055602e6040516d29aa2922a2aa1029a7a62224a2a960911b8152610145600e8201522061ffff19815416905560286040516722a72327a921a2a960c11b815261014560088201522061ffff19815416905560276040516627a32324a1a2a960c91b815261014560078201522061ffff19815416905560276040516621a0a82a20a4a760c91b815261014560078201522061ffff19815416905560276040516611d1539154905360ca1b815261014560078201522061ffff198154169055602b6040516a23a0a723902622a0a222a960a91b8152610145600b8201522061ffff198154169055602460405163424f535360e01b815261014560048201522061ffff1981541690556040516122ee81614ff1565b6000815260208101906000825261235062ffffff604083016000815261ffff806001606087019660008852602860405167141493d4d41150d560c21b815261014160088201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161237481614ff1565b69021e19e0c9bab240000081526020810190600182526123de62ffffff604083016103e8815261ffff8060016060870196600a885260266040516526a2a6a122a960d11b815261014160068201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161240281614ff1565b69043c33c1937564800000815260208101906002825261246d62ffffff604083016107d0815261ffff8060016060870196600a8852602760405166242aa9aa2622a960c91b815261014160078201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161249181614ff1565b69065a4da25d3016c00000815260208101906003825261250362ffffff60408301611388815261ffff8060016060870196600a8852602e6040516d29aa2922a2aa1029a7a62224a2a960911b8152610141600e8201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161252781614ff1565b690a968163f0a57b400000815260208101906005825261259362ffffff60408301612710815261ffff8060016060870196600a885260286040516722a72327a921a2a960c11b815261014160088201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b19161790556040516125b781614ff1565b69152d02c7e14af680000081526020810190600a825261262262ffffff60408301613a98815261ffff8060016060870196600a885260276040516627a32324a1a2a960c91b815261014160078201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161264681614ff1565b6934f086f3b33b6840000081526020810190601982526126b162ffffff60408301614e20815261ffff8060016060870196600a885260276040516621a0a82a20a4a760c91b815261014160078201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b19161790556040516126d581614ff1565b6969e10de76676d0800000815260208101906032825261274062ffffff60408301617530815261ffff8060016060870196600a885260276040516611d1539154905360ca1b815261014160078201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905560405161276481614ff1565b69d3c21bcecceda100000081526020810190606482526127d362ffffff60408301619c40815261ffff8060016060870196600f8852602b6040516a23a0a723902622a0a222a960a91b8152610141600b8201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b19161790556040516127f781614ff1565b6a02116545850052128000008152602081019060fa825261286062ffffff6040830161c350815261ffff8060016060870196600f8852602460405163424f535360e01b815261014160048201522090518155019651161661ffff19865416178555511683615c10565b5160ff60281b82549160281b169060ff60281b191617905561287e57005b61ff0019600054166000557f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498602060405160018152a1005b634e487b7160e01b600052604160045260246000fd5b909260206128f16001928460ff885116919060ff809160031b9316831b921b19161790565b94019101612073565b6101386000527ff79a63dcec80ed75c82f36161f17b9c2f407860160383a7be0a0ee7962c527ae805462ffffff16815561295b91601f0160051c017ff79a63dcec80ed75c82f36161f17b9c2f407860160383a7be0a0ee7962c527af6159b8565b82612061565b61ffff19166101011760005584611f5d565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b50303b158015611f475750600160ff821614611f47565b50600160ff821610611f40565b34610823576020366003190112610823576001600160a01b03612a14614f2f565b166000526101426020526040600020805490612a2f826150ef565b91612a3d604051938461505e565b80835260208301809260005260206000206000915b838310612ac057848660405191829160208301906020845251809152604083019060408160051b85010192916000905b828210612a9157505050500390f35b91936001919395506020612ab08192603f198a82030186528851614f5b565b9601920192018594939192612a82565b60036020600192612ad085615224565b815201920192019190612a52565b346108235760a0366003190112610823576004356001600160401b03811161082357612b0e9036906004016150d1565b612b16615106565b90612b1f6151a1565b6084359160ff831680930361082357612bad9161ffff80600162ffffff94612b45615cb8565b612b87602060405192612b5784614ff1565b6024358452858285019c168c52886040850198168852606084019a8b5281604051938285809451938492016157ce565b810161014181520301902090518155019651161661ffff19865416178555511683615c10565b51815465ff0000000000191660289190911b60ff60281b16179055005b3461082357600036600319011261082357602061013654604051908152f35b3461082357606036600319011261082357612c02614f0f565b612c0a614f1f565b906044359060ff82168092036108235760ff90612c25615cb8565b1691606483118015612d2b575b8015612d21575b610af55760ff9060405193612c4d8561500c565b845216602083015260408201526101385460036101385580600310612cba575b50610138600052602060002060009160005b60038110612c8c57505055005b90926020612cb16001928460ff885116919060ff809160031b9316831b921b19161790565b94019101612c7f565b6101386000527ff79a63dcec80ed75c82f36161f17b9c2f407860160383a7be0a0ee7962c527ae805462ffffff168155612d1b91601f0160051c017ff79a63dcec80ed75c82f36161f17b9c2f407860160383a7be0a0ee7962c527af6159b8565b81612c6d565b5060648211612c39565b50606460ff821611612c32565b3461082357602036600319011261082357610019612d54614f2f565b612d5c615cb8565b615c2c565b34610823576060366003190112610823576004356024359061ffff8216809203610823576044359062ffffff8216809203610823576100199261ffff91612da6615cb8565b8360408051612db48161500c565b838152846020820152015261013a551661ffff1961013b54161761013b5564ffffff000061013b549160101b169064ffffff000019161761013b55565b3461082357600036600319011261082357602060ff6101395416604051908152f35b3461082357604036600319011261082357612e2c614f2f565b60243590612e38615cb8565b8115610af5576040516370a0823160e01b81523060048201526001600160a01b039190911690602081602481855afa90811561083057600091612edc575b508211610ae45760405163a9059cbb60e01b81523360048201526024810192909252602090829060449082906000905af190811561083057600091612ebd575015610ad357005b612ed6915060203d60201161106357611055818361505e565b81610acb565b90506020813d602011612f06575b81612ef76020938361505e565b81010312610823575183612e76565b3d9150612eea565b3461082357602036600319011261082357612f27614f2f565b612f2f6157a3565b5060018060a01b031660005261014060205260a0604060002063ffffffff60405191612f5a83615027565b818154938481528160018401541692602082019384528260036002830154926040850193845201549481608060608601958289168752019660201c168652604051978852511660208701525160408601525116606084015251166080820152f35b34610823576000366003190112610823576097546040516001600160a01b039091168152602090f35b3461082357604036600319011261082357600435602435613003615d10565b61300b615d54565b61012d546040516370a0823160e01b81523360048201526001600160a01b0390911690602081602481855afa908115610830576000916131f6575b5082116117fa57604051636eb1769f60e11b81526020818061306c303360048401615633565b0381855afa908115610830576000916131c4575b50821161102a57602060ff61013954166044604051809481936367c05ed960e01b835288600484015260248301525afa90811561083057600091613192575b508110610af55760206131276000923384526101468352604084206130e5868254615687565b90556130f48161013354615687565b6101335561012d546040516323b872dd60e01b81529485936001600160a01b039092169284928391303360048501615665565b03925af190811561083057600091613173575b5015610ad3576040519081527f1127e24bcbd5e76f9e15cc9ba6972b781e0b33e58347337c0a5e994d4868342860203392a2600160fb55005b61318c915060203d60201161106357611055818361505e565b8261313a565b90506020813d6020116131bc575b816131ad6020938361505e565b810103126108235751836130bf565b3d91506131a0565b90506020813d6020116131ee575b816131df6020938361505e565b81010312610823575184613080565b3d91506131d2565b90506020813d602011613220575b816132116020938361505e565b81010312610823575184613046565b3d9150613204565b3461082357600036600319011261082357613241615d10565b613249615d54565b3360005261014460205260246040600020613266610131546151b3565b50610130546040516344d7b31560e11b81523360048201529260009184919082906001600160a01b03165afa9182156108305760009182918394613634575b508215808061362c575b80613623575b611de157478411610ae45761012e546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa908115610830576000916135f1575b508311610ae45761330e848354615687565b82556001820161331f848254615687565b905560038201805463ffffffff19164263ffffffff16179055156135b9575b8161352d575b8351613391575b50907fd48017f8fc60ac35ced01680518c1b007f6d5fcf6867aef68546ad421b29c9a59160405191825260208201526060604082015280610d9a33946060830190614fbd565b91929060005b6101315480821015613500576133ac826155fe565b905460039190911b1c6001600160a01b03166133cc575b50600101613397565b6133d5826155fe565b60018060a01b0391549060031b1c1690600286019081549081106134a6575b506134696000926020926134276134168761340f818c615991565b519361561b565b91909283549260031b92831c615687565b82548719831b1916911b17905561343e8588615991565b5160405163a9059cbb60e01b8152336004820152602481019190915293849283919082906044820190565b03925af190811561083057600091613488575b5015610ad357856133c3565b6134a0915060203d811161106357611055818361505e565b8661347c565b96919392949590965b610131548110156134ef57875490600160401b8210156128b6576134da8260018094018b558a61561b565b8154906000199060031b1b19169055016134af565b5090959094939192906134696133f4565b509193925090507fd48017f8fc60ac35ced01680518c1b007f6d5fcf6867aef68546ad421b29c9a561334b565b61353a8261013654615687565b6101365561012e5460405163a9059cbb60e01b81523360048201526024810184905290602090829060449082906000906001600160a01b03165af19081156108305760009161359a575b5061334457632185bbe960e01b60005260046000fd5b6135b3915060203d60201161106357611055818361505e565b85613584565b6135c68361013554615687565b61013555600080808086335af16135db615be0565b5061333e57632185bbe960e01b60005260046000fd5b90506020813d60201161361b575b8161360c6020938361505e565b810103126108235751866132fc565b3d91506135ff565b508451156132b5565b5082156132af565b9150925061364b913d8091833e61159a818361505e565b92846132a5565b346108235761366036615117565b613668615d10565b613670615d54565b61ffff8151163360005261014260205261ffff60406000205416913360005261013f602052604060002054918015610af55733600052610142602052604060002060001985019061ffff8211610942576136cd91610e97916151f2565b9361ffff855116156117fa57613979575b92602081018051916000955b845187101561380757600095865b85518110156137fb5761ffff61370e8a89615991565b511661ffff61371d8389615991565b51161461372c576001016136f8565b90939297919496506001908751838301908184116109425761375d6137576137669361ffff936151e5565b8b615991565b51169189615991565b5261012f546001600160a01b031661ffff6137818489615991565b511690803b1561082357604051632142170760e11b815230600482015233602482015261ffff9290921660448301526000908290606490829084905af18015610830576137ea575b505b156137dd5760010195909194926136ea565b610bd661ffff9186615991565b60006137f59161505e565b886137c9565b509291969093956137cb565b9492613819610ed782518751906151e5565b908151613934575b508561ffff835116039261ffff84116109425761ffff61385f941683525263ffffffff421660408201523360005261014260205260406000206159cf565b336000526101426020526040600020546138a8575b50610d9a7f8062d6c146a1b0936b5b8dd244693cf579fe2b5af516678c1f4f8e8f347d876291604051918291339583615b97565b60006138b791610db333615560565b03915afa9182156108305761390860207f8062d6c146a1b0936b5b8dd244693cf579fe2b5af516678c1f4f8e8f347d876294610d9a94600091611ce5575081604051938285809451938492016157ce565b810161014581520301902061ffff61392281835416615b84565b1661ffff198254161790559150613874565b959260009592959491945b855181101561396b578061ffff6139586001938b615991565b51166139648289615991565b520161393f565b509295509293909386613821565b610130548451604051637dd46cc160e01b81526004810186905261ffff909116602482015290600090829060449082906001600160a01b03165afa908115610830576139dd91602091600091611ce5575081604051938285809451938492016157ce565b810161014581520301902061ffff6139f7818354166158d6565b1661ffff198254161790556136de565b346108235760203660031901126108235760043561013854811015610823576000610138548210156107e55760209160f8838361013860ff9552208260051c01549160031b161c16604051908152f35b3461082357600036600319011261082357604051806020610131549283815201809261013160005260206000209060005b818110613aea5750505081613a9e91038261505e565b6040519182916020830190602084525180915260408301919060005b818110613ac8575050500390f35b82516001600160a01b0316845285945060209384019390920191600101613aba565b82546001600160a01b0316845260209093019260019283019201613a88565b3461082357600036600319011261082357613b22615cb8565b609780546001600160a01b031981169091556000906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b3461082357600036600319011261082357602063ffffffff6101375416604051908152f35b3461082357600036600319011261082357602062ffffff6101395460081c16604051908152f35b346108235760003660031901126108235761013d54613bd0816150ef565b90613bde604051928361505e565b80825261013d60009081526020830191907f311617e6f2abe00ca92b0da56c014828817049e78441cf034e4dd4feba529625835b838310613d2657848660405191829160208301906020845251809152604083019060408160051b85010192916000905b828210613c5157505050500390f35b919360019193955060208091603f1989820301855287519063ffffffff825116815282820151838201526040820151604082015261018061ffff81613ca760608601516101a060608701526101a0860190614fbd565b948260808201511660808601528260a08201511660a08601528260c08201511660c08601528260e08201511660e086015282610100820151166101008601528261012082015116610120860152826101408201511661014086015282610160820151166101608601520151169101529601920192018594939192613c42565b60056020600192613d36856158e7565b815201920192019190613c12565b3461082357600036600319011261082357613d5d615d10565b613d65615d54565b3360005261013f602052604060002060018060a01b03610130541660405191638ca1a34560e01b8352336004840152602083602481855afa92831561083057600093614066575b506040516344d7b31560e11b815233600482015291600083602481845afa801561083057600093600091614044575b5082549384156117fa5761012d546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa90811561083057600091614012575b508511610ae4576002840195865463ffffffff42161061400157806115aa57508015801590613ff8575b61156357505033600052610142602052604060002054613f41575b508054600080835560018301805464ffffffffff19169055909355600301805463ffffffff191690555061013254613e9f9082906151e5565b6101325561012d5460405163a9059cbb60e01b81523360048201526024810183905290602090829060449082906000906001600160a01b03165af190811561083057600091613f22575b5015610ad3576040519081527f5c879a554f3e9522fb42e4979579ce936c485c1092dc49d9cc16869dc458620160203392a2600160fb55005b613f3b915060203d60201161106357611055818361505e565b82613ee9565b613f849260009161ffff613f5433615560565b51604051637dd46cc160e01b815260048101949094521661ffff1660248301529093849190829081906044820190565b03915afa8015610830576020613fb291600394600091613fdd575081604051938285809451938492016157ce565b810161014581520301902061ffff613fcc818354166158d6565b1661ffff1982541617905583613e66565b613ff291503d806000833e610e5e818361505e565b86610e0a565b50811515613e4b565b6349793d0560e01b60005260046000fd5b90506020813d60201161403c575b8161402d6020938361505e565b81010312610823575187613e21565b3d9150614020565b905061405c9193503d806000833e61159a818361505e565b5092909285613ddb565b90926020823d602011614092575b816140816020938361505e565b81010312610c255750519183613dac565b3d9150614074565b3461082357600036600319011261082357602060ff60c954166040519015158152f35b34610823576000366003190112610823577f000000000000000000000000211b580107ae76fed8938a5ed04ff0fb940fb5db6001600160a01b03163003614116576020604051600080516020615f3f8339815191528152f35b60405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c6044820152771b1959081d1a1c9bdd59da0819195b1959d85d1958d85b1b60421b6064820152608490fd5b34610823576020366003190112610823576001600160a01b0361419d614f2f565b166000526101466020526020604060002054604051908152f35b6040366003190112610823576141cb614f2f565b6024356001600160401b0381116108235736602382011215610823576141fb90369060248160040135910161509a565b906142547f000000000000000000000000211b580107ae76fed8938a5ed04ff0fb940fb5db6001600160a01b0316614235308214156156e1565b600080516020615f3f833981519152546001600160a01b031614615742565b61425c615cb8565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615614290576100199150615e53565b6040516352d1902d60e01b81526001600160a01b03821690602081600481855afa60009181614491575b5061431b5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608490fd5b600080516020615f3f8339815191520361443a5761433882615e53565b604051907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2825115801590614432575b61437257005b813b156143e157506000828192602061001995519201905af4614393615be0565b604051916143a260608461505e565b602783527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c6020840152660819985a5b195960ca1b6040840152615ee4565b62461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608490fd5b50600161436c565b60405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608490fd5b9091506020813d6020116144bd575b816144ad6020938361505e565b81010312610823575190856142ba565b3d91506144a0565b34610823576020366003190112610823576144de614f2f565b6144e6615cb8565b61013080546001600160a01b0319166001600160a01b0392909216919091179055005b34610823576020366003190112610823576004356001600160401b0381116108235761ffff6145426020610a1c819436906004016150d1565b81016101458152030190205416604051908152f35b3461082357602036600319011261082357614570614f2f565b6145786157a3565b5060018060a01b031660005261013f60205260a0604060002063ffffffff6040516145a281615027565b82549283825260ff60018201548460208501818316815283604087019360201c168352608082600360028801549760608a019889520154169601958652604051978852511660208701525116604085015251606084015251166080820152f35b346108235760003660031901126108235761013c546040516001600160a01b039091168152602090f35b3461082357602036600319011261082357614645614f2f565b61467e7f000000000000000000000000211b580107ae76fed8938a5ed04ff0fb940fb5db6001600160a01b0316614235308214156156e1565b614686615cb8565b602090604051614696838261505e565b6000815282810190601f1984013683377f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156146dc5750506100199150615e53565b6040516352d1902d60e01b81526001600160a01b038416908581600481855afa600091816148d8575b506147665760405162461bcd60e51b815260048101879052602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608490fd5b600080516020615f3f833981519152036148815761478384615e53565b604051907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2815115801590614879575b6147bd57005b833b1561482857506100199392600092839251915af46147db615be0565b907f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c6040519361480c60608661505e565b60278552840152660819985a5b195960ca1b6040840152615ee4565b62461bcd60e51b815260048101859052602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608490fd5b5060006147b7565b60405162461bcd60e51b815260048101869052602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608490fd5b9091508681813d8311614900575b6148f0818361505e565b8101031261082357519087614705565b503d6148e6565b34610823576020366003190112610823576149866020614925614f2f565b60018060a01b03811660005261013f825261ffff61494860406000205492615560565b51610130546040516340b5f39d60e11b81526004810194909452911661ffff166024830152909283916001600160a01b031690829081906044820190565b03915afa8015610830576000906149a3575b602090604051908152f35b506020813d6020116149ce575b816149bd6020938361505e565b810103126108235760209051614998565b3d91506149b0565b3461082357600036600319011261082357606061013a5462ffffff61013b5460405192835261ffff8116602084015260101c166040820152f35b3461082357602036600319011261082357614a29614f2f565b600060408051614a388161500c565b828152826020820152015260018060a01b03166000526101436020526060604060002063ffffffff60405191614a6d8361500c565b548160ff82161515938481528160406020830192828660081c168452019360281c1683526040519485525116602084015251166040820152f35b3461082357602036600319011261082357614ac0614f2f565b60006060604051614ad081614ff1565b828152826020820152816040820152015260018060a01b03166000526101446020526040600020604051614b0381614ff1565b815481526001820154916020820192835263ffffffff614b66816003614b2b60028601615694565b9460408701958652015416926060850193845260405195869560208752516020870152516040860152516080606086015260a0850190614fbd565b91511660808301520390f35b3461082357600036600319011261082357602061013554604051908152f35b3461082357602036600319011261082357600435614bad615cb8565b8015610af55761012d546040516370a0823160e01b81523360048201526001600160a01b0390911690602081602481855afa90811561083057600091614cd0575b5082116117fa57604051636eb1769f60e11b815260208180614c14303360048401615633565b0381855afa90811561083057600091614c9e575b50821161102a57602060405180926323b872dd60e01b825281600081614c5388303360048501615665565b03925af190811561083057600091614c7f575b5015610ad357614c799061013354615687565b61013355005b614c98915060203d60201161106357611055818361505e565b82614c66565b90506020813d602011614cc8575b81614cb96020938361505e565b81010312610823575183614c28565b3d9150614cac565b90506020813d602011614cfa575b81614ceb6020938361505e565b81010312610823575183614bee565b3d9150614cde565b3461082357602036600319011261082357614d1b614f2f565b614d23615cb8565b610131546001600160a01b039091169060005b818110614de957506040516318160ddd60e01b8152602081600481865afa90811561083057600091614db7575b5015614da657600160401b8110156128b657806001614d869201610131556155fe565b81546001600160a01b0360039290921b91821b191692901b919091179055005b634043ee0160e01b60005260046000fd5b90506020813d602011614de1575b81614dd26020938361505e565b81010312610823575183614d63565b3d9150614dc5565b82614df3826155fe565b905460039190911b1c6001600160a01b031614614e1257600101614d36565b6314bb0be160e11b60005260046000fd5b3461082357602036600319011261082357614e5b614e47614e42614f2f565b615560565b604051918291602083526020830190614f5b565b0390f35b3461082357608036600319011261082357614e78614f2f565b50614e81614f45565b506064356001600160401b03811161082357366023820112156108235780600401356001600160401b038111610823573691016024011161082357604051630a85bd0160e11b8152602090f35b3461082357602036600319011261082357614ee7614f0f565b614eef615cb8565b61013c805460ff60a01b191660a09290921b60ff60a01b16919091179055005b6004359060ff8216820361082357565b6024359060ff8216820361082357565b600435906001600160a01b038216820361082357565b602435906001600160a01b038216820361082357565b90606081019161ffff815116825260208101519260606020840152835180915260206080840194019060005b818110614fa35750505063ffffffff6040809201511691015290565b825161ffff16865260209586019590920191600101614f87565b906020808351928381520192019060005b818110614fdb5750505090565b8251845260209384019390920191600101614fce565b608081019081106001600160401b038211176128b657604052565b606081019081106001600160401b038211176128b657604052565b60a081019081106001600160401b038211176128b657604052565b6101a081019081106001600160401b038211176128b657604052565b90601f801991011681019081106001600160401b038211176128b657604052565b6001600160401b0381116128b657601f01601f191660200190565b9291926150a68261507f565b916150b4604051938461505e565b829481845281830111610823578281602093846000960137010152565b9080601f83011215610823578160206150ec9335910161509a565b90565b6001600160401b0381116128b65760051b60200190565b6044359061ffff8216820361082357565b602060031982011261082357600435906001600160401b03821161082357806023830112156108235781600401359061514f826150ef565b9261515d604051948561505e565b8284526024602085019360051b82010191821161082357602401915b8183106151865750505090565b823561ffff8116810361082357815260209283019201615179565b6064359062ffffff8216820361082357565b906151bd826150ef565b6151ca604051918261505e565b82815280926151db601f19916150ef565b0190602036910137565b9190820391821161094257565b805482101561520e576000526003602060002091020190600090565b634e487b7160e01b600052603260045260246000fd5b906040516152318161500c565b809261ffff8154168252600181016040519081602082549182815201916000526020600020906000915b81600f84011061547e57846002946040979463ffffffff9794615300945491818110615469575b818110615451575b81811061543a575b818110615422575b81811061540b575b8181106153f3575b8181106153db575b8181106153c3575b8181106153ab575b818110615393575b81811061537b575b818110615363575b81811061534b575b818110615333575b81811061531b575b1061530d575b50038261505e565b6020860152015416910152565b60f01c8152602001386152f8565b92602060019161ffff8560e01c1681520193016152f2565b92602060019161ffff8560d01c1681520193016152ea565b92602060019161ffff8560c01c1681520193016152e2565b92602060019161ffff8560b01c1681520193016152da565b92602060019161ffff8560a01c1681520193016152d2565b92602060019161ffff8560901c1681520193016152ca565b92602060019161ffff8560801c1681520193016152c2565b92602060019161ffff8560701c1681520193016152ba565b92602060019161ffff8560601c1681520193016152b2565b92602060019161ffff8560501c1681520193016152aa565b92602060019161ffff858e1c1681520193016152a2565b92602060019161ffff8560301c16815201930161529a565b92602060019161ffff85831c168152019301615292565b92602060019161ffff8560101c16815201930161528a565b92602060019161ffff85168152019301615282565b926001610200601092865461ffff8116825261ffff81861c16602083015261ffff8160201c16604083015261ffff8160301c16606083015261ffff8160401c16608083015261ffff8160501c1660a083015261ffff8160601c1660c083015261ffff8160701c1660e083015261ffff8160801c1661010083015261ffff8160901c1661012083015261ffff8160a01c1661014083015261ffff8160b01c1661016083015261ffff8160c01c1661018083015261ffff8160d01c166101a083015261ffff8160e01c166101c083015260f01c6101e082015201940192019161525b565b60405161556c8161500c565b6000815260606020820152600060408201525060018060a01b031680600052610142602052604060002054156155c7576000908152610142602052604090208054600019810191908211610942576150ec91610e97916151f2565b5060206040516155d7828261505e565b600081526000368137604051916155ed8361500c565b600083528201526000604082015290565b6101315481101561520e5761013160005260206000200190600090565b805482101561520e5760005260206000200190600090565b6001600160a01b0391821681529116602082015260400190565b90816020910312610823575180151581036108235790565b6001600160a01b03918216815291166020820152604081019190915260600190565b9190820180921161094257565b906040519182815491828252602082019060005260206000209260005b8181106156c85750506156c69250038361505e565b565b84548352600194850194879450602090930192016156b1565b156156e857565b60405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201526b19195b1959d85d1958d85b1b60a21b6064820152608490fd5b1561574957565b60405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201526b6163746976652070726f787960a01b6064820152608490fd5b604051906157b082615027565b60006080838281528260208201528260408201528260608201520152565b60005b8381106157e15750506000910152565b81810151838201526020016157d1565b9091606082840312610823578151926020830151926040810151906001600160401b03821161082357019080601f83011215610823578151615832816150ef565b92615840604051948561505e565b81845260208085019260051b82010192831161082357602001905b8282106158685750505090565b815181526020918201910161585b565b602081830312610823578051906001600160401b038211610823570181601f820112156108235780516158aa8161507f565b926158b8604051948561505e565b81845260208284010111610823576150ec91602080850191016157ce565b61ffff168015610942576000190190565b906040516158f481615042565b61018061ffff6004839563ffffffff8154168552600181015460208601526002810154604086015261592860038201615694565b606086015201548181166080850152818160101c1660a0850152818160201c1660c0850152818160301c1660e0850152818160401c16610100850152818160501c16610120850152818160601c16610140850152818160701c1661016085015260801c16910152565b805182101561520e5760209160051b010190565b8181029291811591840414171561094257565b8181106159c3575050565b600081556001016159b8565b8054600160401b8110156128b6576159ec916001820181556151f2565b919091615b6e5761ffff808251161661ffff198354161782556001820160208201518051906001600160401b0382116128b657600160401b82116128b6576020908354838555808410615b1c575b50019160005260206000208160041c9160005b838110615adb5750600f198116900380615a86575b50505050600263ffffffff604081930151169201911663ffffffff19825416179055565b9260009360005b818110615aa8575050500155600263ffffffff604081615a62565b9091946020615ad160019261ffff8951169085851b61ffff809160031b9316831b921b19161790565b9601929101615a8d565b6000805b60108110615af4575083820155600101615a4d565b865190969160019160209161ffff60048b901b81811b199092169216901b1792019601615adf565b615b4c908560005283600020600f80870160041c820192601e8860011b1680615b52575b500160041c01906159b8565b38615a3a565b600019850190815490600019908a0360031b1c16905538615b40565b634e487b7160e01b600052600060045260246000fd5b61ffff1661ffff81146109425760010190565b606060209161ffff604082019416815260408382015284518094520192019060005b818110615bc65750505090565b825161ffff16845260209384019390920191600101615bb9565b3d15615c0b573d90615bf18261507f565b91615bff604051938461505e565b82523d6000602084013e565b606090565b9064ffffff000082549160101b169064ffffff00001916179055565b60005b61013154811015615c8657615c43816155fe565b905460039190911b1c6001600160a01b0390811690831614615c6757600101615c2f565b615c7191506155fe565b81549060018060a01b039060031b1b19169055565b63d997d28d60e01b60005260046000fd5b61013d5481101561520e5761013d6000526005602060002091020190600090565b6097546001600160a01b03163303615ccc57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b60ff60c95416615d1c57565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b600260fb5414615d6557600260fb55565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b609780546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b15615dfa57565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b803b15615e8957600080516020615f3f83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b60405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b90919015615ef0575090565b815115615f005750805190602001fd5b6044604051809262461bcd60e51b825260206004830152615f3081518092816024860152602086860191016157ce565b601f01601f19168101030190fdfe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbca2646970667358221220b349fe187343da9ab531cde4c3e451c7106369fda86a1d2b7911aab5156b1aef64736f6c634300081a0033

Block Transaction Gas Used Reward
view all blocks validated

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

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.