lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.21
/**
 * @dev Set start date
 * @param _start uint Time start
 */
function setStartDate(uint _start) public onlyOwner returns(bool) {
        require(_start > now);
        require(requireOnce);

        stages[0].start = _start;
        stages[0].stop = _start.add(stages[0].duration);
        stages[1].start = stages[0].stop;
        stages[1].stop = stages[1].start.add(stages[1].duration);
        stages[2].start = stages[1].stop;
        stages[2].stop = stages[2].start.add(stages[2].duration);
        stages[3].start = stages[2].stop;
        stages[3].stop = stages[3].start.add(stages[3].duration);

        return true;
    }
// Solidity 0.6.12
/**
 * This function transfer `_usdtAmount` USDT to the smart contract
 * and calculate the amount of Lyn then send Lyn to the buyer
 */
function buy(uint256 _usdtAmount) onlyBuyable() external {
        // Calculate lyn amount
        uint256 lynAmount = _usdtAmount.mul(LYN_DECIMAL).div(marketPrice);

        // Transfer usdt to this contract
        usdtToken.transferFrom(msg.sender, address(this), _usdtAmount);

        // Transfer lyn to buyer
        lynToken.transfer(msg.sender, lynAmount);

        emit Buy(msg.sender, _usdtAmount, lynAmount);
    }
// Solidity 0.4.15
/* Constructor taking
 * resqueAccountHash: keccak256(address resqueAccount);
 * authorityAccount: address of authorityAccount that will set data for withdrawing to Emergency account
 * kwHash: keccak256("your keyword phrase");
 * photoHshs: array of keccak256(keccak256(data_of_yourphoto.pdf)) - hashes of photo files taken for this NYX Account. 
 */
function NYX(bytes32 resqueAccountHash, address authorityAccount, bytes32 kwHash, bytes32[10] photoHshs) {
        owner = msg.sender;
        resqueHash = resqueAccountHash;
        authority = authorityAccount;
        keywordHash = kwHash;
        // save photo hashes as state forever
        uint8 x = 0;
        while(x < photoHshs.length)
        {
            photoHashes[x] = photoHshs[x];
            x++;
        }
    }
// Solidity 0.4.15
// Switch on/off Last Chance function
function toggleLastChance(bool useResqueAccountAddress) onlyByOwner()
	{
	    // Only allowed in normal stage to prevent changing this by stolen Owner's account
	    require(stage == Stages.Normal);
	    // Toggle Last Chance function flag
		lastChanceEnabled = !lastChanceEnabled;
		// If set to true knowing of Resque address (not key or password) will be required to use Last Chance function
		lastChanceUseResqueAccountAddress = useResqueAccountAddress;
	}
// Solidity 0.4.15
// Standard transfer Ether using Owner account
function transferByOwner(address recipient, uint amount) onlyByOwner() payable {
        // Only in Normal stage possible
        require(stage == Stages.Normal);
        // Amount must not exeed this.balance
        require(amount <= this.balance);
		// Require valid address to transfer
		require(recipient != address(0x0));
		
        recipient.transfer(amount);
        // This is used by Last Chance function
		lastExpenseTime = now;
    }
// Solidity 0.4.15
/// Withdraw to Resque Account in case of loosing Owner account access
function withdrawByResque() onlyByResque() {
        // If not already requested (see below)
        if(stage != Stages.ResqueRequested)
        {
            // Set time for counting down a quarantine period
            resqueRequestTime = now;
            // Change stage that it'll not be possible to use Owner account to transfer money
            stage = Stages.ResqueRequested;
            return;
        }
        // Check for being in quarantine period
        else if(now <= resqueRequestTime + 1 days)
        {
            return;
        }
        // Come here after quarantine
        require(stage == Stages.ResqueRequested);
        msg.sender.transfer(this.balance);
    }
// Solidity 0.4.15
/* 
 * Setting Emergency Account in case of loosing access to Owner and Resque accounts
 * emergencyAccountHash: keccak256("your keyword phrase", address ResqueAccount)
 * photoHash: keccak256("one_of_your_photofile.pdf_data_passed_to_constructor_of_this_NYX_Account_upon_creation")
 */
function setEmergencyAccount(bytes32 emergencyAccountHash, bytes32 photoHash) onlyByAuthority() {
        require(photoHash != 0x0 && emergencyAccountHash != 0x0);
        /// First check that photoHash is one of those that exist in this NYX Account
        uint8 x = 0;
        bool authorized = false;
        while(x < photoHashes.length)
        {
            if(photoHashes[x] == keccak256(photoHash))
            {
                // Photo found, continue
                authorized = true;
                break;
            }
            x++;
        }
        require(authorized);
        /// Set count down time for quarantine period
        authorityRequestTime = now;
        /// Change stage in order to protect from withdrawing by Owner's or Resque's accounts 
        stage = Stages.AuthorityRequested;
        /// Set supplied hash that will be used to withdraw to Emergency account after quarantine
		emergencyHash = emergencyAccountHash;
    }
// Solidity 0.4.15
/*
 * Allows optionally unauthorized withdrawal to any address after loosing 
 * all authorization assets such as keyword phrase, photo files, private keys/passwords
 */
function lastChance(address recipient, address resqueAccount)
	{
	    /// Last Chance works only if was previosly enabled AND after 2 months since last outgoing transaction
		if(!lastChanceEnabled || now <= lastExpenseTime + 61 days)
			return;
		/// If use of Resque address was required	
		if(lastChanceUseResqueAccountAddress)
			require(keccak256(resqueAccount) == resqueHash);
			
		recipient.transfer(this.balance);			
	}
// Solidity 0.4.21
// Transfer the balance from simple account to account in the fund
function fundTransferIn(address _fundManager, address _to, uint256 _amount) public {
        require(fundManagers[_fundManager]);
        require(!fundManagers[msg.sender]);

        require(balances[msg.sender] >= _amount);
        require(_amount > 0);

        balances[msg.sender] = balances[msg.sender].sub(_amount);
        balances[_fundManager] = balances[_fundManager].add(_amount);
        fundBalances[_fundManager][_to] = fundBalances[_fundManager][_to].add(_amount);

        emit FundTransferIn(msg.sender, _fundManager, _to, _amount);
        emit Transfer(msg.sender, _fundManager, _amount);
    }
// Solidity 0.4.21
// Transfer the balance between two accounts within the fund
function fundTransferWithin(address _from, address _to, uint256 _amount) public {
        require(fundManagers[msg.sender]);

        require(_amount > 0);
        require(balances[msg.sender] >= _amount);
        require(fundBalances[msg.sender][_from] >= _amount);

        fundBalances[msg.sender][_from] = fundBalances[msg.sender][_from].sub(_amount);
        fundBalances[msg.sender][_to] = fundBalances[msg.sender][_to].add(_amount);

        if (fundBalances[msg.sender][_from] == 0){
            delete fundBalances[msg.sender][_from];
        }

        emit FundTransferWithin(msg.sender, _from, _to, _amount);
    }
// Solidity 0.4.21
// destroy tokens that belong to the fund you control
// this decreases that account's balance, fund balance, total supply
function fundBurn(address _fundAccount, uint256 _amount) public onlyFundManager {
        require(fundManagers[msg.sender]);
        require(balances[msg.sender] != 0);
        require(fundBalances[msg.sender][_fundAccount] > 0);
        require(_amount > 0);
        require(_amount <= fundBalances[msg.sender][_fundAccount]);

        assert(_amount <= totalSupply);
        assert(_amount <= balances[msg.sender]);

        totalSupply = totalSupply.sub(_amount);
        balances[msg.sender] = balances[msg.sender].sub(_amount);
        fundBalances[msg.sender][_fundAccount] = fundBalances[msg.sender][_fundAccount].sub(_amount);

        emit FundBurn(msg.sender, _fundAccount, _amount);
    }
// Solidity 0.7.6
/**
 * @dev Generates the class based on a pre-defined distribution
 * 1 = Pilot, 2 = Engineer, 3 = Miner, 4 = Merchant, 5 = Scientist
 * @param _seed Generator seed to derive from
 */
function generateClass(bytes32 _seed) public pure returns (uint) {
    bytes32 seed = _seed.derive("class");
    uint roll = uint(seed.getIntBetween(1, 10001));
    uint[5] memory classes = [ uint(703), 2770, 7122, 8837, 10000 ];

    for (uint i = 0; i < 5; i++) {
      if (roll <= classes[i]) {
        return i + 1;
      }
    }

    return 1;
  }
// Solidity 0.7.6
/**
 * @dev Generates clothes based on the sex and class
 * 1-3 = Light spacesuit, 4-6 = Heavy spacesuit, 7-9 = Lab coat, 10-12 = Industrial, 12-15 = Rebel, 16-18 = Station
 * @param _seed Generator seed to derive from
 * @param _class The class of the crew member
 */
function generateClothes(bytes32 _seed, uint _class) public pure returns (uint) {
    bytes32 seed = _seed.derive("clothes");
    uint roll = uint(seed.getIntBetween(1, 10001));
    uint outfit = 0;

    uint[6][5] memory outfits = [
      [ uint(3333), 3333, 3333, 3333, 6666, 10000 ],
      [ uint(2500), 5000, 5000, 7500, 7500, 10000 ],
      [ uint(2500), 5000, 5000, 7500, 7500, 10000 ],
      [ uint(5000), 5000, 5000, 5000, 5000, 10000 ],
      [ uint(3333), 3333, 6666, 6666, 6666, 10000 ]
    ];

    for (uint i = 0; i < 6; i++) {
      if (roll <= outfits[_class - 1][i]) {
        outfit = i;
        break;
      }
    }

    seed = _seed.derive("clothesVariation");
    roll = uint(seed.getIntBetween(1, 4));
    return (outfit * 3) + roll;
  }
// Solidity 0.7.6
/**
 * @dev Generates hair based on the sex
 * 0 = Bald, 1 - 5 = Male hair, 6 - 11 = Female hair
 * @param _seed Generator seed to derive from
 * @param _sex The sex of the crew member
 */
function generateHair(bytes32 _seed, uint _sex) public pure returns (uint) {
    bytes32 seed = _seed.derive("hair");
    uint style;

    if (_sex == 1) {
      style = uint(seed.getIntBetween(0, 6));
    } else {
      style = uint(seed.getIntBetween(0, 7));
    }

    if (style == 0) {
      return 0;
    } else {
      return style + (_sex - 1) * 5;
    }
  }
// Solidity 0.7.6
/**
 * @dev Generates facial hair, piercings, scars depending on sex
 * 0 = None, 1 = Scar, 2 = Piercings, 3 - 7 = Facial hair
 * @param _seed Generator seed to derive from
 * @param _sex The sex of the crew member
 */
function generateFacialFeatures(bytes32 _seed, uint _sex) public pure returns (uint) {
    bytes32 seed = _seed.derive("facialFeatures");
    uint feature = uint(seed.getIntBetween(0, 3));

    if (_sex == 1 && feature == 2) {
      seed = _seed.derive("facialHair");
      return uint(seed.getIntBetween(3, 8));
    } else {
      return feature;
    }
  }
// Solidity 0.7.6
/**
 * @dev Generates a potential head piece based on class
 * 0 = None, 1 = Goggles, 2 = Glasses, 3 = Patch, 4 = Mask, 5 = Helmet
 * @param _seed Generator seed to derive from
 * @param _mod Modifier that increases chances of more rare items
 */
function generateHeadPiece(bytes32 _seed, uint _class, uint _mod) public pure returns (uint) {
    bytes32 seed = _seed.derive("headPiece");
    uint roll = uint(seed.getIntBetween(int128(_mod), 10001));
    uint[6][5] memory headPieces = [
      [ uint(6667), 6667, 8445, 8889, 9778, 10000 ],
      [ uint(6667), 7619, 9524, 9524, 9524, 10000 ],
      [ uint(6667), 8572, 8572, 9524, 9524, 10000 ],
      [ uint(6667), 6667, 7778, 7778, 10000, 10000 ],
      [ uint(6667), 6667, 8572, 9048, 10000, 10000 ]
    ];

    for (uint i = 0; i < 6; i++) {
      if (roll <= headPieces[_class - 1][i]) {
        return i;
      }
    }

    return 0;
  }
// Solidity 0.8.7
// mint functions
function ownerMint(address to_, uint amount_) external onlyOwner {
        require((totalSupply() + amount_) <= maxTokens, "Amount Exceeds Maximum Tokens!");
        for (uint i = 0; i < amount_; i++) {
            _mint(to_, totalSupply());
        }
    }
// Solidity 0.8.7
// special overrides 
function transferFrom(address from_, address to_, uint tokenId_) public override {
        // if Spore contract is initiated, do a hook, if not, just do basic behavior
        if ( Spore != iSpore(address(0x0)) ) {
            Spore.updateReward(from_, to_, tokenId_);
        }
        ERC721.transferFrom(from_, to_, tokenId_);
    }
// Solidity 0.8.11
// claim erc721
function claimERC721(
        string memory _nftKey,
        address _nftContract,
        address _owner,
        uint256 _tokenId
    ) public payable nonReentrant {
        require(msg.value > 0, "Price must be greater than zero"); //check price must be greater than zero
        require(vaultItemData[_nftKey] == msg.value, "Invalid Bid Price");

        // send payment to NFT Owner
        claims[claimPointer]=Claim(
            payable(msg.sender),
            _nftContract,
            _owner,
            _tokenId,
            msg.value,
            0,
            "",
            false
        );
        claimPointer++;
    }
// Solidity 0.8.11
//claim erc1155
function claimERC1155(
        string memory _nftKey,
        address _nftContract,
        address _owner,
        uint256 _amount,
        uint256 _tokenId,
        bytes memory _data
    ) public payable nonReentrant {
        require(msg.value > 0, "Price must be greater than zero"); //check price must be greater than zero
        require(vaultItemData[_nftKey] == msg.value, "Invalid Bid Price");
        

        claims[claimPointer]=Claim(
            payable(msg.sender),
            _nftContract,
            _owner,
            _tokenId,
            msg.value,
            _amount,
            _data,
            false
        );
        claimPointer++;
    }
// Solidity 0.4.24
/**
 * @dev Used to calculate and store the amount of claimable FIN ERC20 from existing FIN point balances
 * @param _recordAddress - the registered address assigned to FIN ERC20 claiming
 * @param _finPointAmount - the original amount of FIN points to be moved, this param should always be entered as base units
 * i.e., 1 FIN = 10**18 base units
 * @param _applyClaimRate - flag to apply the claim rate or not, any Finterra Technologies company FIN point allocations
 * are strictly moved at one to one and do not recive the claim (airdrop) bonus applied to FIN point user balances
 */
function recordCreate(address _recordAddress, uint256 _finPointAmount, bool _applyClaimRate) public onlyOwner canRecord {
        require(_finPointAmount >= 100000); // minimum allowed FIN 0.000000000001 (in base units) to avoid large rounding errors

        uint256 finERC20Amount;

        if(_applyClaimRate == true) {
            finERC20Amount = _finPointAmount.mul(claimRate).div(100);
        } else {
            finERC20Amount = _finPointAmount;
        }

        claimableFIN[_recordAddress] = claimableFIN[_recordAddress].add(finERC20Amount);

        emit FINRecordCreate(_recordAddress, _finPointAmount, claimableFIN[_recordAddress]);
    }
// Solidity 0.4.24
/**
 * @dev Function to set the migration contract address
 * @return True if the operation was successful.
 */
function setMigrationAddress(FINERC20Migrate _finERC20MigrationContract) public onlyOwner returns (bool) {
        // check that this FIN ERC20 deployment is the migration contract's attached ERC20 token
        require(_finERC20MigrationContract.getERC20() == address(this));

        finERC20MigrationContract = _finERC20MigrationContract;
        emit SetMigrationAddress(_finERC20MigrationContract);
        return true;
    }
// Solidity 0.4.24
/**
 * @dev Function to set the TimeLock contract address
 * @return True if the operation was successful.
 */
function setTimeLockAddress(TimeLock _timeLockContract) public onlyOwner returns (bool) {
        // check that this FIN ERC20 deployment is the timelock contract's attached ERC20 token
        require(_timeLockContract.getERC20() == address(this));

        timeLockContract = _timeLockContract;
        emit SetTimeLockAddress(_timeLockContract);
        return true;
    }
// Solidity 0.4.24
/**
 * @dev Function to start the migration period
 * @return True if the operation was successful.
 */
function startMigration() onlyOwner public returns (bool) {
        require(migrationStart == false);
        // check that the FIN migration contract address is set
        require(finERC20MigrationContract != address(0));
        // // check that the TimeLock contract address is set
        require(timeLockContract != address(0));

        migrationStart = true;
        emit MigrationStarted();

        return true;
    }
// Solidity 0.8.6
//   function addLiquidityETH(uint256 tokenAmount) external payable {
//     // approve token transfer to cover all possible scenarios
//     _approve(address(this), address(uniswapV2Router), tokenAmount);
//     // add the liquidity
//     uniswapV2Router.addLiquidityETH{value: msg.value}(
//         address(this),
//         tokenAmount,
//         0, // slippage is unavoidable
//         0, // slippage is unavoidable
//         msg.sender,
//         block.timestamp
//     );
// }
function _approve(address owner, address spender, uint256 amount) internal {
        require(owner != address(0), "IERC20: approve from the zero address");
        require(spender != address(0), "IERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }
// Solidity 0.6.12
/**
 * @dev Function to calculate the interest using a compounded interest rate formula
 * To avoid expensive exponentiation, the calculation is performed using a binomial approximation:
 *
 *  (1+x)^n = 1+n*x+[n/2*(n-1)]*x^2+[n/6*(n-1)*(n-2)*x^3...
 *
 * The approximation slightly underpays liquidity providers and undercharges borrowers, with the advantage of great gas cost reductions
 * The whitepaper contains reference to the approximation and a table showing the margin of error per different time periods
 *
 * @param rate The interest rate, in ray
 * @param lastUpdateTimestamp The timestamp of the last update of the interest
 * @return The interest rate compounded during the timeDelta, in ray
 **/
function calculateCompoundedInterest(
    uint256 rate,
    uint40 lastUpdateTimestamp,
    uint256 currentTimestamp
  ) internal pure returns (uint256) {
    //solhint-disable-next-line
    uint256 exp = currentTimestamp.sub(uint256(lastUpdateTimestamp));

    if (exp == 0) {
      return WadRayMath.ray();
    }

    uint256 expMinusOne = exp - 1;

    uint256 expMinusTwo = exp > 2 ? exp - 2 : 0;

    uint256 ratePerSecond = rate / _SECONDS_PER_YEAR;

    uint256 basePowerTwo = ratePerSecond.rayMul(ratePerSecond);
    uint256 basePowerThree = basePowerTwo.rayMul(ratePerSecond);

    uint256 secondTerm = exp.mul(expMinusOne).mul(basePowerTwo) / 2;
    uint256 thirdTerm = exp.mul(expMinusOne).mul(expMinusTwo).mul(basePowerThree) / 6;

    return WadRayMath.ray().add(ratePerSecond.mul(exp)).add(secondTerm).add(thirdTerm);
  }
// Solidity 0.4.24
/**
 * @dev transfer token for a specified address with call custom function external data
 * @param _to The address to transfer to.
 * @param _value The amount to be transferred.
 * @param _data The data to call tokenFallback function.
 * @param _fallback The function name and params to call external function
 */
function transfer(address _to, uint256 _value, bytes _data, string _fallback) public whenNotPaused returns (bool) {
    require( _to != address(0));
    
    if (isContract(_to)) {            
      balances[msg.sender] = balances[msg.sender].sub(_value);
      balances[_to] = balances[_to].add(_value);

      assert(_to.call.value(0)(bytes4(keccak256(abi.encodePacked(_fallback))), msg.sender, _value, _data));
      
      if (_data.length == 0) {
        emit Transfer(msg.sender, _to, _value);
      } else {
        emit Transfer(msg.sender, _to, _value);
        emit Transfer(msg.sender, _to, _value, _data);
      }
      return true;
    } else {
      return transferToAddress(msg.sender, _to, _value, _data);
    }
  }
// Solidity 0.6.12
/**
 * @dev Deposit ETH/ERC20_Token.
 * @param _asset: token address to deposit. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
 * @param _amount: token amount to deposit.
 */
function deposit(address _asset, uint256 _amount) external payable override {
    //Get cyToken address from mapping
    address cyTokenAddr = IFujiMappings(_getMappingAddr()).addressMapping(_asset);

    //Enter and/or ensure collateral market is enacted
    _enterCollatMarket(cyTokenAddr);

    if (_isETH(_asset)) {
      // Transform ETH to WETH
      IWeth(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).deposit{ value: _amount }();
      _asset = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
    }

    // Create reference to the ERC20 contract
    IERC20 erc20token = IERC20(_asset);

    // Create a reference to the cyToken contract
    ICyErc20 cyToken = ICyErc20(cyTokenAddr);

    //Checks, Vault balance of ERC20 to make deposit
    require(erc20token.balanceOf(address(this)) >= _amount, "Not enough Balance");

    //Approve to move ERC20tokens
    erc20token.uniApprove(address(cyTokenAddr), _amount);

    // IronBank Protocol mints cyTokens, trhow error if not
    require(cyToken.mint(_amount) == 0, "Deposit-failed");
  }
// Solidity 0.6.12
/**
 * @dev Payback borrowed ETH/ERC20_Token.
 * @param _asset token address to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
 * @param _amount: token amount to payback.
 */
function payback(address _asset, uint256 _amount) external payable override {
    //Get cyToken address from mapping
    address cyTokenAddr = IFujiMappings(_getMappingAddr()).addressMapping(_asset);

    if (_isETH(_asset)) {
      // Transform ETH to WETH
      IWeth(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).deposit{ value: _amount }();
      _asset = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
    }

    // Create reference to the ERC20 contract
    IERC20 erc20token = IERC20(_asset);

    // Create a reference to the corresponding cyToken contract
    ICyErc20 cyToken = ICyErc20(cyTokenAddr);

    // Check there is enough balance to pay
    require(erc20token.balanceOf(address(this)) >= _amount, "Not-enough-token");
    erc20token.uniApprove(address(cyTokenAddr), _amount);
    cyToken.repayBorrow(_amount);
  }
// Solidity 0.6.12
/**
 * @dev Returns the current borrowing rate (APR) of a ETH/ERC20_Token, in ray(1e27).
 * @param _asset: token address to query the current borrowing rate.
 */
function getBorrowRateFor(address _asset) external view override returns (uint256) {
    address cyTokenAddr = IFujiMappings(_getMappingAddr()).addressMapping(_asset);

    //Block Rate transformed for common mantissa for Fuji in ray (1e27), Note: IronBank uses base 1e18
    uint256 bRateperBlock = (IGenCyToken(cyTokenAddr).borrowRatePerBlock()).mul(10**9);

    // The approximate number of blocks per year that is assumed by the IronBank interest rate model
    uint256 blocksperYear = 2102400;
    return bRateperBlock.mul(blocksperYear);
  }
// Solidity 0.8.7
/**
 * @dev Cheks if the msg.sender that have ADMIN permition.
 */
function _checkAdmin()internal view {
    bool isAdmin = false;
    for (uint i = 0; i < ADMINS.length; i++){
      if(!isAdmin)
        isAdmin = ADMINS[i] == msg.sender;
      else 
        break;
    }

    if (!isAdmin) {
      revert(
        string(
          abi.encodePacked(
              "Address is not admin"
          )
        )
      );
    }
  }
// Solidity 0.8.7
/**
 * @dev Cheks the hash message and signature for the buy function.
 * @param  _hash the bytes for the message hash
 * @param _signature the signature of the message
 * @param _account the account of the signer
 */
function _checkHash(bytes32 _hash, bytes memory _signature, address _account ) internal view returns (bool) {
      bytes32 senderHash = _senderMessageHash();
      if (senderHash != _hash) {
          return false;
      }
      return _hash.recover(_signature) == _account;
  }