lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.10
/**
 * @dev Set token extension contract address.
 * The extension contract can for example verify "ERC1400TokensValidator" or "ERC1400TokensChecker" interfaces.
 * If the extension is an "ERC1400TokensValidator", it will be called everytime a transfer is executed.
 * @param extension Address of the extension contract.
 * @param interfaceLabel Interface label of extension contract.
 * @param removeOldExtensionRoles If set to 'true', the roles of the old extension(minter, controller) will be removed extension.
 * @param addMinterRoleForExtension If set to 'true', the extension contract will be added as minter.
 * @param addControllerRoleForExtension If set to 'true', the extension contract will be added as controller.
 */
function _setTokenExtension(address extension, string memory interfaceLabel, bool removeOldExtensionRoles, bool addMinterRoleForExtension, bool addControllerRoleForExtension) internal {
    address oldExtension = interfaceAddr(address(this), interfaceLabel);

    if (oldExtension != address(0) && removeOldExtensionRoles) {
      if(isMinter(oldExtension)) {
        _removeMinter(oldExtension);
      }
      _isController[oldExtension] = false;
    }

    ERC1820Client.setInterfaceImplementation(interfaceLabel, extension);
    if(addMinterRoleForExtension && !isMinter(extension)) {
      _addMinter(extension);
    }
    if (addControllerRoleForExtension) {
      _isController[extension] = true;
    }
  }
// Solidity 0.4.16
/**
 * @dev Function to check the amount of tokens that an owner allowed to a spender.
 * @param _totalSupply total supply of the token.
 * @param _name token name e.g QASH Token.
 * @param _symbol token symbol e.g QASH.
 * @param _decimals amount of decimals.
 */
function LMToken(uint256 _totalSupply, string _name, string _symbol, uint8 _decimals) {
        balances[msg.sender] = _totalSupply;    // Give the creator all initial tokens
        totalSupply = _totalSupply;
        name = _name;
        symbol = _symbol;
        decimals = _decimals;
    }
// Solidity 0.5.13
/**
 * @dev Get total supply of all TrueCurrency
 * Equal to deposit backed TrueCurrency plus debt backed TrueCurrency
 * @return total supply in trueCurrency
 */
function totalSupply() public view returns (uint256) {
        // if supply in opportunity finOp, return supply of deposits + debt
        // otherwise call super to return normal totalSupply
        if (opportunityRewardSupply() != 0) {
            return totalSupply_.add(opportunityTotalSupply());
        }
        return totalSupply_;
    }
// Solidity 0.5.13
/**
 * @dev Get balance of TrueCurrency including rewards for an address
 *
 * @param _who address of account to get balanceOf for
 * @return balance total balance of address including rewards
 */
function balanceOf(address _who) public view returns (uint256) {
        // if trueReward enabled, return token value of reward balance
        // otherwise call token balanceOf
        if (trueRewardEnabled(_who)) {
            return _toToken(rewardTokenBalance(_who, opportunity()), opportunity());
        }
        return super.balanceOf(_who);
    }
// Solidity 0.5.13
/**
 * @dev Enable TrueReward and deposit user balance into opportunity.
 * Currently supports a single financial opportunity
 */
function enableTrueReward() external {
        // require TrueReward is not enabled
        require(registry.hasAttribute(msg.sender, IS_TRUEREWARDS_WHITELISTED), "must be whitelisted to enable TrueRewards");
        require(!trueRewardEnabled(msg.sender), "TrueReward already enabled");

        // get sender balance
        uint balance = _getBalance(msg.sender);

        if (balance != 0) {
            // mint reward token
            mintRewardToken(msg.sender, balance, opportunity());
        }

        // set reward distribution
        // we set max distribution since we only have one opportunity
        _setDistribution(maxRewardProportion, opportunity());

        // emit enable event
        emit TrueRewardEnabled(msg.sender);
        //emit Transfer(address(0), msg.sender, balance);
    }
// Solidity 0.5.13
/**
 * @dev Disable TrueReward and withdraw user balance from opportunity.
 */
function disableTrueReward() external {
        // require TrueReward is enabled
        require(trueRewardEnabled(msg.sender), "TrueReward already disabled");
        // get balance
        uint rewardBalance = rewardTokenBalance(msg.sender, opportunity());

        // remove reward distribution
        _removeDistribution(opportunity());

        if (rewardBalance > 0) {
            // redeem for token
            redeemRewardToken(msg.sender, rewardBalance, opportunity());
        }

        // emit disable event
        emit TrueRewardDisabled(msg.sender);
        // emit Transfer(msg.sender, address(0), zTrueCurrency);
    }
// Solidity 0.5.13
/**
 * @dev mint function for TrueRewardBackedToken
 * Mints TrueCurrency backed by debt
 * When we add multiple opportunities, this needs to work for mutliple interfaces
 */
function mint(address _to, uint256 _value) public onlyOwner {
        // check if to address is enabled
        bool toEnabled = trueRewardEnabled(_to);

        // if to enabled, mint to this contract and deposit into finOp
        if (toEnabled) {
            // mint to this contract
            super.mint(address(this), _value);
            // transfer minted amount to target receiver
            _transferAllArgs(address(this), _to, _value);
        }
        // otherwise call normal mint process
        else {
            super.mint(_to, _value);
        }
    }
// Solidity 0.5.13
/**
 * @dev Transfer helper function for TrueRewardBackedToken
 */
function _transferAllArgs(address _from, address _to, uint256 _value) internal {
        // 1. Both sender and receiver are disabled
        // Exchange is in TrueCurrency -> call the normal transfer function
        if (!trueRewardEnabled(_from) && !trueRewardEnabled(_to)) {
            // sender not enabled receiver not enabled
            super._transferAllArgs(_from, _to, _value);
            return;
        }
        require(balanceOf(_from) >= _value, "not enough balance");

        // require account is not blacklisted and check if hook is registered
        (address finalTo, bool hasHook) = _requireCanTransfer(_from, _to);

        _value = _transferWithRewards(_from, finalTo, _value);

        // emit transfer event for from
        emit Transfer(_from, _to, _value);
        if (finalTo != _to) {
            emit Transfer(_to, finalTo, _value);
            if (hasHook) {
                TrueCoinReceiver(finalTo).tokenFallback(_to, _value);
            }
        } else {
            if (hasHook) {
                TrueCoinReceiver(finalTo).tokenFallback(_from, _value);
            }
        }
    }
// Solidity 0.8.11
// addListing(): add a point to the registry, including its corresponding price and owner address.
// optional reserved buyer address can be included. 
//
function addListing(uint32 _point, uint96 _price, address _reservedBuyer) external
    {
        // intentionally using isOwner() instead of canTransfer(), which excludes third-party proxy addresses.
        // the exchange owner also has no ability to list anyone else's assets, it can strictly only be the point owner.
        // 
        require(azimuth.isOwner(_point, _msgSender()), "not owner");

        // add the price of the point and the seller address to the registry
        //         
        setRegistryEntry(_point, _msgSender(), _price, _reservedBuyer);        
        
        emit ListingAdded(_point, _price);

    }
// Solidity 0.8.7
//<interface-functions>
function supportsInterface(bytes4 interfaceID) public pure returns (bool) {
        return interfaceID == 0x3b3b57de //addr
        || interfaceID == 0x59d1d43c //text
        || interfaceID == 0x691f3431 //name
        || interfaceID == 0x01ffc9a7; //supportsInterface << [inception]
    }
// Solidity 0.8.7
//</read-functions>
//--------------------------------------------------------------------------------------------//
//<helper-functions>
function addressToString(address _addr) private pure returns(string memory) {
    bytes32 value = bytes32(uint256(uint160(_addr)));
    bytes memory alphabet = "0123456789abcdef";

    bytes memory str = new bytes(51);
    str[0] = "0";
    str[1] = "x";
    for (uint i = 0; i < 20; i++) {
        str[2+i*2] = alphabet[uint(uint8(value[i + 12] >> 4))];
        str[3+i*2] = alphabet[uint(uint8(value[i + 12] & 0x0f))];
        }
    return string(str);
    }
// Solidity 0.8.6
/**
 * @dev 2. Swaps fAsset for mAsset and then deposits to Save/Savings Vault
 * @param _mAsset             mAsset address
 * @param _save               Save address
 * @param _vault              Boosted Savings Vault address
 * @param _feeder             Feeder Pool address
 * @param _fAsset             fAsset address
 * @param _fAssetQuantity     Quantity of fAsset sent
 * @param _minOutputQuantity  Min amount of mAsset to be swapped and deposited
 * @param _stake              Deposit the imAsset in the Savings Vault?
 */
function saveViaSwap(
        address _mAsset,
        address _save,
        address _vault,
        address _feeder,
        address _fAsset,
        uint256 _fAssetQuantity,
        uint256 _minOutputQuantity,
        bool _stake
    ) external {
        _saveViaSwap(
            _mAsset,
            _save,
            _vault,
            _feeder,
            _fAsset,
            _fAssetQuantity,
            _minOutputQuantity,
            _stake,
            address(0)
        );
    }
// Solidity 0.8.6
/**
 * @dev 3. Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,
 *         optionally staking in the Boosted Savings Vault
 * @param _mAsset         mAsset address
 * @param _save           Save address
 * @param _vault          Boosted vault address
 * @param _uniswap        Uniswap router address
 * @param _amountOutMin   Min uniswap output in bAsset units
 * @param _path           Sell path on Uniswap (e.g. [WETH, DAI])
 * @param _minOutMStable  Min amount of mAsset to receive
 * @param _stake          Add the imAsset to the Savings Vault?
 */
function saveViaUniswapETH(
        address _mAsset,
        address _save,
        address _vault,
        address _uniswap,
        uint256 _amountOutMin,
        address[] calldata _path,
        uint256 _minOutMStable,
        bool _stake
    ) external payable {
        _saveViaUniswapETH(
            _mAsset,
            _save,
            _vault,
            _uniswap,
            _amountOutMin,
            _path,
            _minOutMStable,
            _stake,
            address(0)
        );
    }
// Solidity 0.8.6
/**
 * @dev Gets estimated mAsset output from a WETH > bAsset > mAsset trade
 * @param _mAsset       mAsset address
 * @param _uniswap      Uniswap router address
 * @param _ethAmount    ETH amount to sell
 * @param _path         Sell path on Uniswap (e.g. [WETH, DAI])
 */
function estimate_saveViaUniswapETH(
        address _mAsset,
        address _uniswap,
        uint256 _ethAmount,
        address[] calldata _path
    ) external view returns (uint256 out) {
        require(_mAsset != address(0), "Invalid mAsset");
        require(_uniswap != address(0), "Invalid uniswap");

        uint256 estimatedBasset = _getAmountOut(_uniswap, _ethAmount, _path);
        return IMasset(_mAsset).getMintOutput(_path[_path.length - 1], estimatedBasset);
    }
// Solidity 0.8.6
/**
 * @dev 0. Simply saves an mAsset and then into the vault
 * @param _mAsset   mAsset address
 * @param _save     Save address
 * @param _vault    Boosted Savings Vault address
 * @param _amount   Units of mAsset to deposit to savings
 * @param _referrer Referrer address for this deposit.
 */
function _saveAndStake(
        address _mAsset,
        address _save,
        address _vault,
        uint256 _amount,
        bool _stake,
        address _referrer
    ) internal {
        require(_mAsset != address(0), "Invalid mAsset");
        require(_save != address(0), "Invalid save");
        require(_vault != address(0), "Invalid vault");

        // 1. Get the input mAsset
        IERC20(_mAsset).safeTransferFrom(msg.sender, address(this), _amount);

        // 2. Mint imAsset and stake in vault
        _depositAndStake(_save, _vault, _amount, _stake, _referrer);
    }
// Solidity 0.8.6
/** @dev Internal func to deposit into Save and optionally stake in the vault
 * @param _save       Save address
 * @param _vault      Boosted vault address
 * @param _amount     Amount of mAsset to deposit
 * @param _stake      Add the imAsset to the Savings Vault?
 * @param _referrer   Referrer address for this deposit, if any.
 */
function _depositAndStake(
        address _save,
        address _vault,
        uint256 _amount,
        bool _stake,
        address _referrer
    ) internal {
        if (_stake && _referrer != address(0)) {
            uint256 credits = ISavingsContractV3(_save).depositSavings(
                _amount,
                address(this),
                _referrer
            );
            IBoostedVaultWithLockup(_vault).stake(msg.sender, credits);
        } else if (_stake && _referrer == address(0)) {
            uint256 credits = ISavingsContractV3(_save).depositSavings(_amount, address(this));
            IBoostedVaultWithLockup(_vault).stake(msg.sender, credits);
        } else if (!_stake && _referrer != address(0)) {
            ISavingsContractV3(_save).depositSavings(_amount, msg.sender, _referrer);
        } else {
            ISavingsContractV3(_save).depositSavings(_amount, msg.sender);
        }
    }
// Solidity 0.8.6
/**
 * @dev 1. Mints an mAsset and then deposits to Save/Savings Vault
 * @param _mAsset       mAsset address
 * @param _bAsset       bAsset address
 * @param _save         Save address
 * @param _vault        Boosted Savings Vault address
 * @param _amount       Amount of bAsset to mint with
 * @param _minOut       Min amount of mAsset to get back
 * @param _stake        Add the imAsset to the Boosted Savings Vault?
 * @param _referrer     Referrer address for this deposit.
 */
function _saveViaMint(
        address _mAsset,
        address _save,
        address _vault,
        address _bAsset,
        uint256 _amount,
        uint256 _minOut,
        bool _stake,
        address _referrer
    ) internal {
        require(_mAsset != address(0), "Invalid mAsset");
        require(_save != address(0), "Invalid save");
        require(_vault != address(0), "Invalid vault");
        require(_bAsset != address(0), "Invalid bAsset");

        // 1. Get the input bAsset
        IERC20(_bAsset).safeTransferFrom(msg.sender, address(this), _amount);

        // 2. Mint
        uint256 massetsMinted = IMasset(_mAsset).mint(_bAsset, _amount, _minOut, address(this));

        // 3. Mint imAsset and optionally stake in vault
        _depositAndStake(_save, _vault, massetsMinted, _stake, _referrer);
    }
// Solidity 0.8.6
/**
 * @dev Approve mAsset and bAssets, Feeder Pools and fAssets, and Save/vault
 */
function approve(
        address _mAsset,
        address[] calldata _bAssets,
        address[] calldata _fPools,
        address[] calldata _fAssets,
        address _save,
        address _vault
    ) external onlyKeeperOrGovernor {
        _approve(_mAsset, _save);
        _approve(_save, _vault);
        _approve(_bAssets, _mAsset);

        require(_fPools.length == _fAssets.length, "Mismatching fPools/fAssets");
        for (uint256 i = 0; i < _fPools.length; i++) {
            _approve(_fAssets[i], _fPools[i]);
        }
    }
// Solidity 0.4.24
/* This function is used to transfer tokens to a particular address 
 * @param _to receiver address where transfer is to be done
 * @param _value value to be transferred
 */
function transfer(address _to, uint256 _value) public whenNotPaused returns (bool)  {      
        require(balanceOf[msg.sender] > 0);                     
        require(balanceOf[msg.sender] >= _value);                   // Check if the sender has enough  
        require(_to != address(0));                                 // Prevent transfer to 0x0 address. Use burn() instead
        require(_value > 0);	
        require(_to != msg.sender);                                 // Check if sender and receiver is not same
        balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);  // Subtract value from sender
        balanceOf[_to] = balanceOf[_to].add(_value);                // Add the value to the receiver
        emit Transfer(msg.sender, _to, _value);                     // Notify all clients about the transfer events
        return true;
	}
// Solidity 0.4.24
/**
 * This function Burns a specific amount of tokens.
 * @param _value The amount of token to be burned.
 */
function burn(uint256 _value) public onlyOwner {
      require(_value <= balanceOf[msg.sender]);
      // no need to require value <= totalSupply, since that would imply the
      // sender's balance is greater than the totalSupply, which *should* be an assertion failure
      address burner = msg.sender;
      balanceOf[burner] = balanceOf[burner].sub(_value);
      totalSupply = totalSupply.sub(_value);
      emit Burn(burner, _value);
  }
// Solidity 0.8.11
/**
 * @notice Returns royalty reciever address and royalty amount
 * @param _tokenId Token Id
 * @param _salePrice Value to calculate royalty from
 * @return receiver Royalty reciever address
 * @return amount Royalty amount
 */
function royaltyInfo(uint256 _tokenId, uint256 _salePrice)
        external
        view
        override
        returns (address receiver, uint256 amount)
    {
        require(_tokenId > 0);
        receiver = this.owner();
        if (_salePrice <= 100) {
            amount = 0;
        } else {
            amount = _salePrice.mul(5).div(100);
        }
    }
// Solidity 0.8.11
/**
 * @notice Calls when royalty recieved
 */
function onRoyaltiesReceived(
        address _royaltyRecipient,
        address _buyer,
        uint256 _tokenId,
        address _tokenPaid,
        uint256 _amount,
        bytes32 _metadata
    ) external returns (bytes4) {
        emit RoyaltiesReceived(
            _royaltyRecipient,
            _buyer,
            _tokenId,
            _tokenPaid,
            _amount,
            _metadata
        );
        return
            bytes4(
                keccak256(
                    "onRoyaltiesReceived(address,address,uint256,address,uint256,bytes32)"
                )
            );
    }
// Solidity 0.4.18
// ------------------------------------------------------------------------
// 1,000 WALL Tokens per 1 ETH
// ------------------------------------------------------------------------
function () public payable {
        require(now >= startDate && now <= endDate);
        uint tokens;
        if (now <= bonusEnds) {
            tokens = msg.value * 1200;
        } else {
            tokens = msg.value * 1000;
        }
        balances[msg.sender] = safeAdd(balances[msg.sender], tokens);
        _totalSupply = safeAdd(_totalSupply, tokens);
        Transfer(address(0), msg.sender, tokens);
        owner.transfer(msg.value);
    }
// Solidity 0.4.24
/////////////
/// @dev the inflation rate begins at 100% and decreases by 30% every year until it reaches 10%
/// at 10% the rate begins to decrease by 0.5% until it reaches 1%
function adjustInflationRate() private {
      // Make sure adjustInflationRate cannot be called for at least another year
      lastInflationUpdate = now;

      // Decrease inflation rate by 30% each year
      if (inflationRate > 100) {
        inflationRate = inflationRate.sub(300);
      }
      // Inflation rate reaches 10%. Decrease inflation rate by 0.5% from here on out until it reaches 1%.
      else if (inflationRate > 10) {
        inflationRate = inflationRate.sub(5);
      }

      adjustMintRates();
    }
// Solidity 0.4.24
/// @dev adjusts the mint rate when the yearly inflation update is called
function adjustMintRates() internal {

      // Calculate new mint amount of Scale that should be created per year.
      poolMintAmount = totalSupply.mul(inflationRate).div(1000).mul(poolPercentage).div(100);
      ownerMintAmount = totalSupply.mul(inflationRate).div(1000).mul(ownerPercentage).div(100);
      stakingMintAmount = totalSupply.mul(inflationRate).div(1000).mul(stakingPercentage).div(100);

      // Adjust Scale created per-second for each rate
      poolMintRate = calculateFraction(poolMintAmount, 31536000 ether, decimals);
      ownerMintRate = calculateFraction(ownerMintAmount, 31536000 ether, decimals);
      stakingMintRate = calculateFraction(stakingMintAmount, 31536000 ether, decimals);
    }
// Solidity 0.4.24
/// @dev Transfer tokens from the contract to the user when unstaking
/// @param _value uint256 the amount of tokens to be transferred
function transferFromContract(uint _value) internal {

     // Sanity check to make sure we are not transferring more than the contract has
     require(_value <= balances[address(this)]);

     // Add to the msg.sender balance
     balances[msg.sender] = balances[msg.sender].add(_value);
     
     // Subtract from the contract's balance
     balances[address(this)] = balances[address(this)].sub(_value);

     // Fire an event for transfer
     emit Transfer(address(this), msg.sender, _value);
   }
// Solidity 0.4.24
/// @dev stake function reduces the user's total available balance and adds it to their staking balance
/// @param _value how many tokens a user wants to stake
function stakeScale(address _user, uint256 _value) private returns (bool success) {

       // You can only stake / stakeFor as many tokens as you have
       require(_value <= balances[msg.sender]);

       // Require the user is not in power down period
       require(stakeBalances[_user].unstakeTime == 0);

       // Transfer tokens to contract address
       transfer(address(this), _value);

       // Now as a day
       uint _nowAsDay = now.div(timingVariable);

       // Adjust the new staking balance
       uint _newStakeBalance = stakeBalances[_user].stakeBalance.add(_value);

       // If this is the initial stake time, save
       if (stakeBalances[_user].stakeBalance == 0) {
         // Save the time that the stake started
         stakeBalances[_user].initialStakeTime = _nowAsDay;
       }

       // Add stake amount to staked balance
       stakeBalances[_user].stakeBalance = _newStakeBalance;

       // Assign the total amount staked at this day
       stakeBalances[_user].stakePerDay[_nowAsDay] = _newStakeBalance;

       // Increment the total staked tokens
       totalScaleStaked = totalScaleStaked.add(_value);

       // Set the new staking history
       setTotalStakingHistory();

       // Fire an event for newly staked tokens
       emit Stake(_user, _value);

       return true;
   }
// Solidity 0.4.24
/// @dev deposit a user's initial stake plus earnings if the user unstaked at least 14 days ago
function claimStake() external returns (bool) {

      // Require that at least 14 days have passed (days)
      require(now.div(timingVariable).sub(stakeBalances[msg.sender].unstakeTime) >= 14);

      // Get the user's stake balance 
      uint _userStakeBalance = stakeBalances[msg.sender].stakeBalance;

      // Calculate tokens to mint using unstakeTime, rewards are not received during power-down period
      uint _tokensToMint = calculateStakeGains(stakeBalances[msg.sender].unstakeTime);

      // Clear out stored data from mapping
      stakeBalances[msg.sender].stakeBalance = 0;
      stakeBalances[msg.sender].initialStakeTime = 0;
      stakeBalances[msg.sender].unstakeTime = 0;

      // Return the stake balance to the staker
      transferFromContract(_userStakeBalance);

      // Mint the new tokens to the sender
      mint(msg.sender, _tokensToMint);

      // Scale unstaked event
      emit ClaimStake(msg.sender, _userStakeBalance, _tokensToMint);

      return true;
    }