lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/**
 * @dev Grant tokens to a specified address. Please note, that the trustee must have enough ungranted tokens
 * to accomodate the new grant. Otherwise, the call with fail.
 * @param _to address The holder address.
 * @param _value uint256 The amount of tokens to be granted.
 * @param _start uint256 The beginning of the vesting period.
 * @param _cliff uint256 Point in time of the end of the cliff period (when the first installment is made).
 * @param _end uint256 The end of the vesting period.
 * @param _installmentLength uint256 The length of each vesting installment (in seconds).
 * @param _revocable bool Whether the grant is revocable or not.
 */
function granting(address _to, uint256 _value, uint256 _start, uint256 _cliff, uint256 _end,
    uint256 _installmentLength, bool _revocable)
    external onlyOwner 
    {    
        require(_to != address(0));
        
        // Don't allow holder to be this contract.
        require(_to != address(this));
        
        require(_value > 0);
        
        // Require that every holder can be granted tokens only once.
        require(grants[_to].value == 0);
        
        // Require for time ranges to be consistent and valid.
        require(_start <= _cliff && _cliff <= _end);
        
        // Require installment length to be valid and no longer than (end - start).
        require(_installmentLength > 0 && _installmentLength <= _end.sub(_start));
        
        // Grant must not exceed the total amount of tokens currently available for vesting.
        require(totalVesting.add(_value) <= token.balanceOf(address(this)));
        
        // Assign a new grant.
        grants[_to] = Grant({
            value: _value,
            start: _start,
            cliff: _cliff,
            end: _end,
            installmentLength: _installmentLength,
            transferred: 0,
            revocable: _revocable
        });
        
        // Since tokens have been granted, increase the total amount available for vesting.
        totalVesting = totalVesting.add(_value);
        
        emit NewGrant(msg.sender, _to, _value);
    }
// Solidity 0.4.24
/**
 * @dev Calculate amount of vested tokens at a specifc time.
 * @param _grant Grant The vesting grant.
 * @param _time uint256 The time to be checked
 * @return a uint256 Representing the amount of vested tokens of a specific grant.
 */
function calculateVestedTokens(Grant _grant, uint256 _time) private pure returns (uint256) {
        // If we're before the cliff, then nothing is vested.
        if (_time < _grant.cliff) {
            return 0;
        }
       
        // If we're after the end of the vesting period - everything is vested;
        if (_time >= _grant.end) {
            return _grant.value;
        }
       
        // Calculate amount of installments past until now.
        // NOTE result gets floored because of integer division.
        uint256 installmentsPast = _time.sub(_grant.start).div(_grant.installmentLength);
       
        // Calculate amount of days in entire vesting period.
        uint256 vestingDays = _grant.end.sub(_grant.start);
       
        // Calculate and return installments that have passed according to vesting days that have passed.
        return _grant.value.mul(installmentsPast.mul(_grant.installmentLength)).div(vestingDays);
    }
// Solidity 0.8.7
// claim txs will revert if any tokenids are not claimable
function claim(
        uint256[] memory tokenIds,
        uint256[] memory amounts,
        uint256 nonce,
        uint256 timestamp,
        bytes memory signature
    ) external payable override nonReentrant {
        address sender = _msgSender();
        address recovered = ECDSA.recover(
            ECDSA.toEthSignedMessageHash(
                keccak256(
                    abi.encode(sender, tokenIds, amounts, nonce, timestamp)
                )
            ),
            signature
        );
        require(
            tokenIds.length > 0 && tokenIds.length == amounts.length,
            "Array lengths are invalid"
        );
        require(
            recovered == admin() || recovered == owner(),
            "Not authorized to claim"
        );

        _mintBatch(sender, tokenIds, amounts, "");
        delete recovered;
        delete sender;
    }
// Solidity 0.4.24
/**
 * @dev Set an updateManager for an account
 * @param _owner - address of the account to set the updateManager
 * @param _operator - address of the account to be set as the updateManager
 * @param _approved - bool whether the address will be approved or not
 */
function setUpdateManager(address _owner, address _operator, bool _approved) external {
    require(_operator != msg.sender, "The operator should be different from owner");
    require(
      _owner == msg.sender ||
      _isApprovedForAll(_owner, msg.sender),
      "Unauthorized user"
    );

    updateManager[_owner][_operator] = _approved;

    emit UpdateManager(
      _owner,
      _operator,
      msg.sender,
      _approved
    );
  }
// Solidity 0.4.24
/**
 * @dev Register an account balance
 * @notice Register land Balance
 */
function registerBalance() external {
    require(!registeredBalance[msg.sender], "Register Balance::The user is already registered");

    // Get balance of the sender
    uint256 currentBalance = landBalance.balanceOf(msg.sender);
    if (currentBalance > 0) {
      require(
        landBalance.destroyTokens(msg.sender, currentBalance),
        "Register Balance::Could not destroy tokens"
      );
    }

    // Set balance as registered
    registeredBalance[msg.sender] = true;

    // Get LAND balance
    uint256 newBalance = _balanceOf(msg.sender);

    // Generate Tokens
    require(
      landBalance.generateTokens(msg.sender, newBalance),
      "Register Balance::Could not generate tokens"
    );
  }
// Solidity 0.4.24
/**
 * @dev Unregister an account balance
 * @notice Unregister land Balance
 */
function unregisterBalance() external {
    require(registeredBalance[msg.sender], "Unregister Balance::The user not registered");

    // Set balance as unregistered
    registeredBalance[msg.sender] = false;

    // Get balance
    uint256 currentBalance = landBalance.balanceOf(msg.sender);

    // Destroy Tokens
    require(
      landBalance.destroyTokens(msg.sender, currentBalance),
      "Unregister Balance::Could not destroy tokens"
    );
  }
// Solidity 0.8.7
/**
 * @dev Public mints a new token
 * @param hash The hash of the token
 * @param signature The signature of the token
 */
function mint(bytes32 hash, bytes memory signature) external payable onlySender nonReentrant {
        require(!publicMintPaused, "Mint is paused");

        require(
            hash ==
                keccak256(
                    abi.encode(msg.sender, balanceOf(msg.sender), address(this))
                ),
            "Invalid hash"
        );
        require(
            ECDSA.recover(ECDSA.toEthSignedMessageHash(hash), signature) ==
                _defender,
            "Invalid signature"
        );

        uint256 amount = _getMintAmount(msg.value);

        require(
            amount <= maxPerTx,
            "Minting amount exceeds max per transaction"
        );

        require(
            balanceOf(msg.sender) + amount <= maxPerWallet,
            "You can't mint more than max per wallet"
        );

        _safeMint(msg.sender, amount);
    }
// Solidity 0.8.7
/**
 * @dev get the minting amount for the given value
 * @param value The value of the transaction
 */
function _getMintAmount(uint256 value) internal view returns (uint256) {
        uint256 remainder = value % mintPrice;
        require(remainder == 0, "Send a divisible amount of eth");

        uint256 amount = value / mintPrice;
        require(amount > 0, "Amount to mint is 0");
        require(
            (totalSupply() + amount) <= collectionSize - reservedSize,
            "Sold out!"
        );
        return amount;
    }
// Solidity 0.5.0
// Forward ERC20 methods to upgraded contract if this one is deprecated
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) {
        require(!isBlackListed[msg.sender]);
        require(!isBlackListed[_from]);
        require(!isBlackListed[_to]);
        if (deprecated) {
            return UpgradedStandardToken(upgradedAddress).transferFromByLegacy(msg.sender, _from, _to, _value);
        } else {
            return super.transferFrom(_from, _to, _value);
        }
    }
// Solidity 0.4.23
/**
 * @notice Transfers tokens held by timelock to beneficiary.
 */
function release() public {
        uint256 nowTime = block.timestamp;
        uint256 passTime = nowTime - openingTime;
        uint256 weeksnow = passTime/2419200;
        require(unfreezed[weeksnow] != 1, "This week we have unfreeze part of the token");
        uint256 amount = getPartReleaseAmount();
        require(amount > 0, "the token has finished released");
        unfreezed[weeksnow] = 1;
        token.transfer(beneficiary, amount);
    }
// Solidity 0.4.23
/**
 *@dev getMonthRelease is the function to get todays month realse
 *
 */
function getPartReleaseAmount() public view returns(uint256){
        uint stage = getStage();
        for( uint i = 0; i <= stage; i++ ) {
            uint256 stageAmount = totalFreeze/2;
        }
        uint256 amount = stageAmount*2419200/126230400;
        return amount;
    }
// Solidity 0.4.23
/**
 *@dev getStage is the function to get which stage the lock is on, four year will change the stage
 *@return uint256
 */
function getStage() public view returns(uint256) {
        uint256 nowTime = block.timestamp;
        uint256 passTime = nowTime - openingTime;
        uint256 stage = passTime/126230400;       //stage is the lock is on, a day is 86400 seconds
        return stage;
    }
// Solidity 0.8.7
/**
 * @dev Mint `count` tokens if requirements are satisfied.
 * 
 */
function mintTokens(uint256 count)
  public
  payable
  nonReentrant{
    require(_isPublicMintEnabled, "Mint disabled");
    require(count > 0 && count <= 100, "You can drop minimum 1, maximum 100 NFTs");
    require(count.add(_tokenIds.current()) < _maxSupply, "Exceeds max supply");
    require(owner() == msg.sender || msg.value >= _mintCost.mul(count),
           "Ether value sent is below the price");
    for(uint i=0; i<count; i++){
        _mint(msg.sender);
     }
  }
// Solidity 0.8.7
/**
 * @dev Mint a token to each Address of `recipients`.
 * Can only be called if requirements are satisfied.
 */
function mintTokens(address[] calldata recipients)
  public
  payable
  nonReentrant{
    require(recipients.length>0,"Missing recipient addresses");
    require(owner() == msg.sender || _isPublicMintEnabled, "Mint disabled");
    require(recipients.length > 0 && recipients.length <= 100, "You can drop minimum 1, maximum 100 NFTs");
    require(recipients.length.add(_tokenIds.current()) < _maxSupply, "Exceeds max supply");
    require(owner() == msg.sender || msg.value >= _mintCost.mul(recipients.length),
           "Ether value sent is below the price");
    for(uint i=0; i<recipients.length; i++){
        _mint(recipients[i]);
     }
  }
// Solidity 0.5.17
// Source: https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol
// call has been separated into its own function in order to take advantage
// of the Solidity's code generator to produce a loop that copies tx.data into memory.
function external_call(address destination, uint value, uint dataOffset, uint dataLength, bytes memory data) internal returns (bool) {
        bool result;
        assembly {
            let x := mload(0x40)   // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
            let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
            result := call(
                sub(gas, 34710),   // 34710 is the value that solidity is currently emitting
                                   // It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
                                   // callNewAccountGas (25000, in case the destination address does not exist and needs creating)
                destination,
                value,
                add(d, dataOffset),
                dataLength,        // Size of the input (in bytes) - this is what fixes the padding problem
                x,
                0                  // Output is ignored, therefore the output size is zero
            )
        }
        return result;
    }
// Solidity 0.6.12
/// @dev Return the amount of token out as liquidation reward for liquidating token in.
/// @param tokenIn Input ERC20 token
/// @param tokenOut Output ERC1155 token
/// @param tokenOutId Output ERC1155 token id
/// @param amountIn Input ERC20 token amount
function convertForLiquidation(
    address tokenIn,
    address tokenOut,
    uint tokenOutId,
    uint amountIn
  ) external view returns (uint) {
    require(whitelistERC1155[tokenOut], 'bad token');
    address tokenOutUnderlying = IERC20Wrapper(tokenOut).getUnderlyingToken(tokenOutId);
    uint rateUnderlying = IERC20Wrapper(tokenOut).getUnderlyingRate(tokenOutId);
    uint liqIncentiveIn = liqIncentives[tokenIn];
    uint liqIncentiveOut = liqIncentives[tokenOutUnderlying];
    require(liqIncentiveIn != 0, 'bad underlying in');
    require(liqIncentiveOut != 0, 'bad underlying out');
    uint pxIn = source.getETHPx(tokenIn);
    uint pxOut = source.getETHPx(tokenOutUnderlying);
    uint amountOut = amountIn.mul(pxIn).div(pxOut);
    amountOut = amountOut.mul(2**112).div(rateUnderlying);
    return amountOut.mul(liqIncentiveIn).mul(liqIncentiveOut).div(10000 * 10000);
  }
// Solidity 0.6.12
/// @dev Return the value of the given input as ETH for collateral purpose.
/// @param token ERC1155 token address to get collateral value
/// @param id ERC1155 token id to get collateral value
/// @param amount Token amount to get collateral value
/// @param owner Token owner address
function asETHCollateral(
    address token,
    uint id,
    uint amount,
    address owner
  ) external view returns (uint) {
    require(whitelistERC1155[token], 'bad token');
    address tokenUnderlying = IERC20Wrapper(token).getUnderlyingToken(id);
    uint rateUnderlying = IERC20Wrapper(token).getUnderlyingRate(id);
    uint amountUnderlying = amount.mul(rateUnderlying).div(2**112);
    uint tier = alphaTier.getAlphaTier(owner);
    uint collFactor = tierTokenFactors[tokenUnderlying][tier].collateralFactor;
    require(liqIncentives[tokenUnderlying] != 0, 'bad underlying collateral');
    require(collFactor != 0, 'bad coll factor');
    uint ethValue = source.getETHPx(tokenUnderlying).mul(amountUnderlying).div(2**112);
    return ethValue.mul(collFactor).div(10000);
  }
// Solidity 0.6.12
/// @dev Return the value of the given input as ETH for borrow purpose.
/// @param token ERC20 token address to get borrow value
/// @param amount ERC20 token amount to get borrow value
/// @param owner Token owner address
function asETHBorrow(
    address token,
    uint amount,
    address owner
  ) external view returns (uint) {
    uint tier = alphaTier.getAlphaTier(owner);
    uint borrFactor = tierTokenFactors[token][tier].borrowFactor;
    require(liqIncentives[token] != 0, 'bad underlying borrow');
    require(borrFactor < 50000, 'bad borr factor');
    uint ethValue = source.getETHPx(token).mul(amount).div(2**112);
    return ethValue.mul(borrFactor).div(10000);
  }
// Solidity 0.5.11
/**
 * Change voting rules
 *
 * Make so that proposals need to be discussed for at least `minutesForDebate/60` hours
 * and all voters combined must own more than `minimumPercentToPassAVote` multiplied by total supply tokens of `tokenAddress` to be executed
 *
 * @param _tokenAddress token address
 * @param _minimumTokensToVote address can vote only if the number of tokens held by address exceed this number
 * @param _minimumPercentToPassAVote proposal can vote only if the sum of tokens held by all voters exceed this number divided by 100 and muliplied by token total supply
 * @param _minutesForDebate the minimum amount of delay between when a proposal is made and when it can be executed
 */
function changeVotingRules(Token _tokenAddress, address _chairmanAddress, uint _minimumTokensToVote, uint _minimumPercentToPassAVote, uint _minutesForDebate) onlyOwner public {
        require(_chairmanAddress != address(0));
        require(_minimumPercentToPassAVote <= 51);
        tokenAddress = Token(_tokenAddress);
        chairmanAddress = _chairmanAddress;
        if (_minimumTokensToVote == 0 ) _minimumTokensToVote = 1;
        minimumTokensToVote = _minimumTokensToVote;
        if (_minimumPercentToPassAVote == 0 ) _minimumPercentToPassAVote = 51;
        minimumQuorum = _minimumPercentToPassAVote;
        debatingPeriodInMinutes = _minutesForDebate;
        emit ChangeOfRules(_minimumTokensToVote, minimumQuorum, debatingPeriodInMinutes, address(tokenAddress), chairmanAddress);
    }
// Solidity 0.5.11
/**
 * Add Proposal
 *
 * Propose to execute transaction
 *
 * @param destination is a transaction destination address
 * @param weiAmount amount of wei
 * @param transactionDescription Description of transaction
 * @param transactionBytecode bytecode of transaction
 */
function newProposal(
        address destination,
        uint weiAmount,
        string memory transactionDescription,
        bytes memory transactionBytecode
    )
        onlyTokenholders public
        returns (uint proposalID)
    {
        proposalID = proposals.length++;
        Proposal storage p = proposals[proposalID];
        p.recipient = destination;
        p.signedByChairman = false;
        p.amount = weiAmount;
        p.description = transactionDescription;
        p.proposalHash = keccak256(abi.encodePacked(destination, weiAmount, transactionBytecode));
        p.minExecutionDate = now + debatingPeriodInMinutes * 1 minutes;
        p.executed = false;
        p.proposalPassed = false;
        p.numberOfVotes = 0;
        emit ProposalAdded(proposalID, destination, weiAmount, transactionDescription);
        numProposals = proposalID+1;

        return proposalID;
    }
// Solidity 0.5.11
/**
 * Sign a proposal
 *
 * Vote `supportsProposal? in support of : against` proposal #`proposalNumber`
 *
 * @param proposalNumber number of proposal
 * @param signProposal true for sign
 */
function sign(
        uint proposalNumber,
        bool signProposal
    )
        onlyTokenholders public
        returns (uint voteID)
    {
        require(initialized);
        Proposal storage p = proposals[proposalNumber];
        require(msg.sender == chairmanAddress);
        require(signProposal == true);

        p.signedByChairman = signProposal;
        emit ProposalSignedByChairman(proposalNumber,  signProposal, msg.sender);
        return proposalNumber;
    }
// Solidity 0.5.11
/**
 * Log a vote for a proposal
 *
 * Vote `supportsProposal? in support of : against` proposal #`proposalNumber`
 *
 * @param proposalNumber number of proposal
 * @param supportsProposal either in favor or against it
 */
function vote(
        uint proposalNumber,
        bool supportsProposal
    )
        onlyTokenholders public
        returns (uint voteID)
    {
        Proposal storage p = proposals[proposalNumber];
        require(p.voted[msg.sender] != true);

        voteID = p.votes.length++;
        p.votes[voteID] = Vote({inSupport: supportsProposal, voter: msg.sender});
        p.voted[msg.sender] = true;
        p.numberOfVotes = voteID +1;
        emit Voted(proposalNumber,  supportsProposal, msg.sender);
        return voteID;
    }
// Solidity 0.4.18
// -------------------------------------------------
// Transfers amount to address
// -------------------------------------------------
function transfer(address _to, uint256 _amount) public notBeforeCrowdfundEnds returns (bool success) {
        require(accounts[msg.sender] >= _amount);         // check amount of balance can be tranfered
        addToBalance(_to, _amount);
        decrementBalance(msg.sender, _amount);
        Transfer(msg.sender, _to, _amount);
        return true;
    }
// Solidity 0.4.18
// -------------------------------------------------
// Finalizes crowdfund. If there are leftover RED, let them overflow to foundation
// -------------------------------------------------
function finalizeCrowdfund() external onlyCrowdfund {
        require(stage == icoStages.PublicSale);
        uint256 amount = balanceOf(crowdfundAddress);
        if (amount > 0) {
            accounts[crowdfundAddress] = 0;
            addToBalance(foundationAddress, amount);
            Transfer(crowdfundAddress, foundationAddress, amount);
        }
        stage = icoStages.Done;
        CrowdfundFinalized(amount);                        // event log
    }
// Solidity 0.4.18
// -------------------------------------------------
// Function to unlock 20% RED to private angels investors
// -------------------------------------------------
function partialUnlockAngelsAccounts(address[] _batchOfAddresses) external onlyOwner notBeforeCrowdfundEnds returns (bool success) {
        require(unlock20Done == false);
        uint256 amount;
        address holder;
        for (uint256 i = 0; i < _batchOfAddresses.length; i++) {
            holder = _batchOfAddresses[i];
            amount = angels[holder].mul(20).div(100);
            angels[holder] = angels[holder].sub(amount);
            addToBalance(holder, amount);
        }
        unlock20Done = true;
        return true;
    }
// Solidity 0.4.18
// -------------------------------------------------
// Function to unlock all remaining RED to private angels investors (after 3 months)
// -------------------------------------------------
function fullUnlockAngelsAccounts(address[] _batchOfAddresses) external onlyOwner checkAngelsLockingPeriod returns (bool success) {
        uint256 amount;
        address holder;
        for (uint256 i = 0; i < _batchOfAddresses.length; i++) {
            holder = _batchOfAddresses[i];
            amount = angels[holder];
            angels[holder] = 0;
            addToBalance(holder, amount);
        }
        return true;
    }
// Solidity 0.4.18
// -------------------------------------------------
// Contract's constructor
// -------------------------------------------------
function REDCrowdfund(address _tokenAddress) public {
        wallet       = 0xc65f0d8a880f3145157117Af73fe2e6e8E60eF3c;  // ICO wallet address
        startsAt     = 1515398400;                         // Jan 8th 2018, 16:00, GMT+8
        endsAt       = 1517385600;                         // Jan 31th 2018, 16:00, GMT+8
        tokenAddress = _tokenAddress;                      // RED token Address
        RED          = REDToken(tokenAddress);
    }
// Solidity 0.4.18
// -------------------------------------------------
// Function to buy RED. One can also buy RED by calling this function directly and send
// it to another destination.
// -------------------------------------------------
function buyTokens(address _to) public crowdfundIsActive onlyWhiteList nonZeroAddress(_to) nonZeroValue payable {
        uint256 weiAmount = msg.value;
        uint256 tokens;
        uint price = 2500;

        if (RED.isEarlyBirdsStage()) {price = 2750;}       // 10% discount for early birds
        tokens = weiAmount * price;
        weiRaised = weiRaised.add(weiAmount);
        wallet.transfer(weiAmount);
        if (!RED.transferFromCrowdfund(_to, tokens)) {revert();}
        TokenPurchase(_to, weiAmount, tokens);
    }