lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/// @notice Calculate the vested and unclaimed days and tokens available for `_grantId` to claim
/// Due to rounding errors once grant duration is reached, returns the entire left grant amount
/// Returns (0, 0) if cliff has not been reached
function calculateGrantClaim(uint256 _grantId) public view returns (uint16, uint256) {
    Grant storage tokenGrant = tokenGrants[_grantId];
    require(tokenGrant.recipient == msg.sender || owner() == msg.sender, '!recipient');

    // For grants created with a future start date, that hasn't been reached, return 0, 0
    if (currentTime() < tokenGrant.startTime) {
      return (0, 0);
    }

    // Check cliff was reached
    uint elapsedTime = currentTime().sub(tokenGrant.startTime);
    uint elapsedDays = elapsedTime.div(SECONDS_PER_DAY);
    if (elapsedDays < tokenGrant.vestingCliff) {
      return (uint16(elapsedDays), 0);
    }

    // If over vesting duration, all tokens vested
    if (elapsedDays >= tokenGrant.vestingDuration) {
      uint256 remainingGrant = tokenGrant.amount.sub(tokenGrant.totalClaimed);
      return (tokenGrant.vestingDuration, remainingGrant);
    } else {
      uint16 daysVested = uint16(elapsedDays.sub(tokenGrant.daysClaimed));
      uint256 amountVestedPerDay = tokenGrant.amount.div(uint256(tokenGrant.vestingDuration));
      uint256 amountVested = uint256(daysVested.mul(amountVestedPerDay));
      return (daysVested, amountVested);
    }
  }
// Solidity 0.6.12
/// @notice Allows a grant recipient to claim their vested tokens. Errors if no tokens have vested
/// It is advised recipients check they are entitled to claim via `calculateGrantClaim` before calling this
function claimVestedTokens(uint256 _grantId) external {
    uint16 daysVested;
    uint256 amountVested;
    (daysVested, amountVested) = calculateGrantClaim(_grantId);
    require(amountVested > 0, "amountVested is 0");

    Grant storage tokenGrant = tokenGrants[_grantId];
    tokenGrant.daysClaimed = uint16(tokenGrant.daysClaimed.add(daysVested));
    tokenGrant.totalClaimed = uint256(tokenGrant.totalClaimed.add(amountVested));
    token.safeTransfer(tokenGrant.recipient, amountVested);
    emit GrantTokensClaimed(tokenGrant.recipient, amountVested);
  }
// Solidity 0.5.17
/**
 * @notice Transfer `tokens` tokens from `src` to `dst` by `spender`
 * @dev Called by both `transfer` and `transferFrom` internally
 * @param spender The address of the account performing the transfer
 * @param src The address of the source account
 * @param dst The address of the destination account
 * @param tokens The number of tokens to transfer
 * @return Whether or not the transfer succeeded
 */
function transferTokens(
        address spender,
        address src,
        address dst,
        uint256 tokens
    ) internal returns (uint256) {
        /* Fail if transfer not allowed */
        uint256 allowed = comptroller.transferAllowed(address(this), src, dst, tokens);
        if (allowed != 0) {
            return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.TRANSFER_COMPTROLLER_REJECTION, allowed);
        }

        /* Do not allow self-transfers */
        if (src == dst) {
            return fail(Error.BAD_INPUT, FailureInfo.TRANSFER_NOT_ALLOWED);
        }

        /* Get the allowance, infinite for the account owner */
        uint256 startingAllowance = 0;
        if (spender == src) {
            startingAllowance = uint256(-1);
        } else {
            startingAllowance = transferAllowances[src][spender];
        }

        /* Do the calculations, checking for {under,over}flow */
        accountTokens[src] = sub_(accountTokens[src], tokens);
        accountTokens[dst] = add_(accountTokens[dst], tokens);

        /* Eat some of the allowance (if necessary) */
        if (startingAllowance != uint256(-1)) {
            transferAllowances[src][spender] = sub_(startingAllowance, tokens);
        }

        /* We emit a Transfer event */
        emit Transfer(src, dst, tokens);

        // unused function
        // comptroller.transferVerify(address(this), src, dst, tokens);

        return uint256(Error.NO_ERROR);
    }
// Solidity 0.5.17
/**
 * @notice Transfers collateral tokens (this market) to the liquidator.
 * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another CToken.
 *  Its absolutely critical to use msg.sender as the seizer cToken and not a parameter.
 * @param seizerToken The contract seizing the collateral (i.e. borrowed cToken)
 * @param liquidator The account receiving seized collateral
 * @param borrower The account having collateral seized
 * @param seizeTokens The number of cTokens to seize
 * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
 */
function seizeInternal(
        address seizerToken,
        address liquidator,
        address borrower,
        uint256 seizeTokens
    ) internal returns (uint256) {
        /* Fail if seize not allowed */
        uint256 allowed = comptroller.seizeAllowed(address(this), seizerToken, liquidator, borrower, seizeTokens);
        if (allowed != 0) {
            return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_SEIZE_COMPTROLLER_REJECTION, allowed);
        }

        /*
         * Return if seizeTokens is zero.
         * Put behind `seizeAllowed` for accuring potential COMP rewards.
         */
        if (seizeTokens == 0) {
            return uint256(Error.NO_ERROR);
        }

        /* Fail if borrower = liquidator */
        if (borrower == liquidator) {
            return fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER);
        }

        /*
         * We calculate the new borrower and liquidator token balances, failing on underflow/overflow:
         *  borrowerTokensNew = accountTokens[borrower] - seizeTokens
         *  liquidatorTokensNew = accountTokens[liquidator] + seizeTokens
         */
        accountTokens[borrower] = sub_(accountTokens[borrower], seizeTokens);
        accountTokens[liquidator] = add_(accountTokens[liquidator], seizeTokens);

        /* Emit a Transfer event */
        emit Transfer(borrower, liquidator, seizeTokens);

        /* We call the defense hook */
        // unused function
        // comptroller.seizeVerify(address(this), seizerToken, liquidator, borrower, seizeTokens);

        return uint256(Error.NO_ERROR);
    }
// Solidity 0.8.4
/** @dev Mint in the public sale
 * @param quantity The quantity of tokens to mint
 */
function publicMint(uint256 quantity) public payable {
        bytes32 _contractState = keccak256(abi.encodePacked(contractState));
        require(
            _contractState == publicMintState,
            "Public minting is not active"
        );
        // check the txn value
        require(
            msg.value >= mintPrice * quantity,
            "Insufficient value for public mint"
        );
        mint(quantity, _contractState);
    }
// Solidity 0.4.24
/**
 * @dev Create a new instance of the SwissCryptoExchange contract.
 * @param _admin             address Admin address
 * @param _feeAccount        address Fee Account address
 * @param _accountLevelsAddr address AccountLevels contract address
 * @param _feeMake           uint256 FeeMake amount
 * @param _feeTake           uint256 FeeTake amount
 * @param _feeRebate         uint256 FeeRebate amount
 */
function SwissCryptoExchange(
    address _admin,
    address _feeAccount,
    address _accountLevelsAddr,
    uint256 _feeMake,
    uint256 _feeTake,
    uint256 _feeRebate
  )
    public
  {
    // Ensure the admin address is valid.
    require(_admin != 0x0);

    // Store the values.
    admin = _admin;
    feeAccount = _feeAccount;
    accountLevelsAddr = _accountLevelsAddr;
    feeMake = _feeMake;
    feeTake = _feeTake;
    feeRebate = _feeRebate;

    // Validate "ethereum address".
    whitelistedTokens[0x0] = true;
  }
// Solidity 0.4.24
/**
 * @dev Change the admin address.
 * @param _admin address The new admin address
 */
function changeAdmin(address _admin) public onlyAdmin {
    // The provided address should be valid and different from the current one.
    require(_admin != 0x0 && admin != _admin);

    // Store the new value.
    admin = _admin;
  }
// Solidity 0.4.24
/**
 * @dev Change the feeTake amount.
 * @param _feeTake uint256 New fee take.
 */
function changeFeeTake(uint256 _feeTake) public onlyAdmin {
    // The new feeTake should be greater than or equal to the feeRebate.
    require(_feeTake >= feeRebate);

    // Store the new value.
    feeTake = _feeTake;
  }
// Solidity 0.4.24
/**
 * @dev Change the feeRebate amount.
 * @param _feeRebate uint256 New fee rebate.
 */
function changeFeeRebate(uint256 _feeRebate) public onlyAdmin {
    // The new feeRebate should be less than or equal to the feeTake.
    require(_feeRebate <= feeTake);

    // Store the new value.
    feeRebate = _feeRebate;
  }
// Solidity 0.4.24
/**
 * @dev Add a ERC20 token contract address to the whitelisted ones.
 * @param token address Address of the contract to be added to the whitelist.
 */
function addWhitelistedTokenAddr(address token) public onlyAdmin {
    // Token address should not be 0x0 (ether) and it should not be already whitelisted.
    require(token != 0x0 && !whitelistedTokens[token]);

    // Change the flag for this contract address to true.
    whitelistedTokens[token] = true;
  }
// Solidity 0.4.24
/**
 * @dev Remove a ERC20 token contract address from the whitelisted ones.
 * @param token address Address of the contract to be removed from the whitelist.
 */
function removeWhitelistedTokenAddr(address token) public onlyAdmin {
    // Token address should not be 0x0 (ether) and it should be whitelisted.
    require(token != 0x0 && whitelistedTokens[token]);

    // Change the flag for this contract address to false.
    whitelistedTokens[token] = false;
  }
// Solidity 0.4.24
/**
 * @dev Add an user address to the whitelisted ones.
 * @param user address Address to be added to the whitelist.
 */
function addWhitelistedUserAddr(address user) public onlyAdmin {
    // Address provided should be valid and not already whitelisted.
    require(user != 0x0 && !whitelistedUsers[user]);

    // Change the flag for this address to false.
    whitelistedUsers[user] = true;
  }
// Solidity 0.4.24
/**
 * @dev Remove an user address from the whitelisted ones.
 * @param user address Address to be removed from the whitelist.
 */
function removeWhitelistedUserAddr(address user) public onlyAdmin {
    // Address provided should be valid and whitelisted.
    require(user != 0x0 && whitelistedUsers[user]);

    // Change the flag for this address to false.
    whitelistedUsers[user] = false;
  }
// Solidity 0.4.24
/**
 * @dev Deposit wei into the exchange contract.
 */
function deposit() public payable {
    // Only whitelisted users can make deposits.
    require(whitelistedUsers[msg.sender]);

    // Add the deposited wei amount to the user balance.
    tokens[0x0][msg.sender] = tokens[0x0][msg.sender].add(msg.value);

    // Trigger the event.
    Deposit(0x0, msg.sender, msg.value, tokens[0x0][msg.sender]);
  }
// Solidity 0.4.24
/**
 * @dev Withdraw wei from the exchange contract back to the user. 
 * @param amount uint256 Wei amount to be withdrawn.
 */
function withdraw(uint256 amount) public {
    // Requester should have enough balance.
    require(tokens[0x0][msg.sender] >= amount);
  
    // Substract the withdrawn wei amount from the user balance.
    tokens[0x0][msg.sender] = tokens[0x0][msg.sender].sub(amount);

    // Transfer the wei to the requester.
    msg.sender.transfer(amount);

    // Trigger the event.
    Withdraw(0x0, msg.sender, amount, tokens[0x0][msg.sender]);
  }
// Solidity 0.4.24
/**
 * @dev Perform a new token deposit to the exchange contract.
 * @dev Remember to call ERC20(address).approve(this, amount) or this contract will not
 *      be able to do the transfer on your behalf.
 * @param token  address Address of the deposited token contract
 * @param amount uint256 Amount to be deposited
 */
function depositToken(address token, uint256 amount)
    public
  {
    // Should not deposit wei using this function and
    // token contract address should be whitelisted.
    require(token != 0x0 && whitelistedTokens[token]);
      
    // Only whitelisted users can make deposits.
    require(whitelistedUsers[msg.sender]);

    // Add the deposited token amount to the user balance.
    tokens[token][msg.sender] = tokens[token][msg.sender].add(amount);
    
    // Transfer tokens from caller to this contract account.
    require(ERC20(token).transferFrom(msg.sender, address(this), amount));
  
    // Trigger the event.    
    Deposit(token, msg.sender, amount, tokens[token][msg.sender]);
  }
// Solidity 0.4.24
/**
 * @dev Withdraw the given token amount from the requester balance.
 * @param token  address Address of the withdrawn token contract
 * @param amount uint256 Amount of tokens to be withdrawn
 */
function withdrawToken(address token, uint256 amount) public {
    // Should not withdraw wei using this function.
    require(token != 0x0);

    // Requester should have enough balance.
    require(tokens[token][msg.sender] >= amount);

    // Substract the withdrawn token amount from the user balance.
    tokens[token][msg.sender] = tokens[token][msg.sender].sub(amount);
    
    // Transfer the tokens to the investor.
    require(ERC20(token).transfer(msg.sender, amount));

    // Trigger the event.
    Withdraw(token, msg.sender, amount, tokens[token][msg.sender]);
  }
// Solidity 0.4.24
/**
 * @dev Place a new order to the this contract. 
 * @param tokenGet   address
 * @param amountGet  uint256
 * @param tokenGive  address
 * @param amountGive uint256
 * @param expires    uint256
 * @param nonce      uint256
 */
function order(
    address tokenGet,
    uint256 amountGet,
    address tokenGive,
    uint256 amountGive,
    uint256 expires,
    uint256 nonce
  )
    public
  {
    // Order placer address should be whitelisted.
    require(whitelistedUsers[msg.sender]);

    // Order tokens addresses should be whitelisted. 
    require(whitelistedTokens[tokenGet] && whitelistedTokens[tokenGive]);

    // Calculate the order hash.
    bytes32 hash = keccak256(address(this), tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
    
    // Store the order.
    orders[msg.sender][hash] = true;

    // Trigger the event.
    Order(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender);
  }
// Solidity 0.4.24
/**
 * @dev Cancel an existing order.
 * @param tokenGet   address
 * @param amountGet  uint256
 * @param tokenGive  address
 * @param amountGive uint256
 * @param expires    uint256
 * @param nonce      uint256
 * @param v          uint8
 * @param r          bytes32
 * @param s          bytes32
 */
function cancelOrder(
    address tokenGet,
    uint256 amountGet,
    address tokenGive,
    uint256 amountGive,
    uint256 expires,
    uint256 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
  )
    public
  {
    // Calculate the order hash.
    bytes32 hash = keccak256(address(this), tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
    
    // Ensure the message validity.
    require(validateOrderHash(hash, msg.sender, v, r, s));
    
    // Fill the order to the requested amount.
    orderFills[msg.sender][hash] = amountGet;

    // Trigger the event.
    Cancel(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender, v, r, s);
  }
// Solidity 0.4.24
/**
 * @dev Perform a trade.
 * @param tokenGet   address
 * @param amountGet  uint256
 * @param tokenGive  address
 * @param amountGive uint256
 * @param expires    uint256
 * @param nonce      uint256
 * @param user       address
 * @param v          uint8
 * @param r          bytes32
 * @param s          bytes32
 * @param amount     uint256 Traded amount - in amountGet terms
 */
function trade(
    address tokenGet,
    uint256 amountGet,
    address tokenGive,
    uint256 amountGive,
    uint256 expires,
    uint256 nonce,
    address user,
    uint8 v,
    bytes32 r,
    bytes32 s,
    uint256 amount 
  )
    public
  {
    // Only whitelisted users can perform trades.
    require(whitelistedUsers[msg.sender]);

    // Only whitelisted tokens can be traded.
    require(whitelistedTokens[tokenGet] && whitelistedTokens[tokenGive]);

    // Expire block number should be greater than current block.
    require(block.number <= expires);

    // Calculate the trade hash.
    bytes32 hash = keccak256(address(this), tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
    
    // Validate the hash.
    require(validateOrderHash(hash, user, v, r, s));

    // Ensure that after the trade the ordered amount will not be excedeed.
    require(SafeMath.add(orderFills[user][hash], amount) <= amountGet); 
    
    // Add the traded amount to the order fill.
    orderFills[user][hash] = orderFills[user][hash].add(amount);

    // Trade balances.
    tradeBalances(tokenGet, amountGet, tokenGive, amountGive, user, amount);
    
    // Trigger the event.
    Trade(tokenGet, amount, tokenGive, SafeMath.mul(amountGive, amount).div(amountGet), user, msg.sender);
  }
// Solidity 0.4.24
/**
 * @dev Check if the trade with provided parameters will pass or not.
 * @param tokenGet   address
 * @param amountGet  uint256
 * @param tokenGive  address
 * @param amountGive uint256
 * @param expires    uint256
 * @param nonce      uint256
 * @param user       address
 * @param v          uint8
 * @param r          bytes32
 * @param s          bytes32
 * @param amount     uint256
 * @param sender     address
 * @return bool
 */
function testTrade(
    address tokenGet,
    uint256 amountGet,
    address tokenGive,
    uint256 amountGive,
    uint256 expires,
    uint256 nonce,
    address user,
    uint8 v,
    bytes32 r,
    bytes32 s,
    uint256 amount,
    address sender
  )
    public
    constant
    returns(bool)
  {
    // Traders should be whitelisted.
    require(whitelistedUsers[user] && whitelistedUsers[sender]);

    // Tokens should be whitelisted.
    require(whitelistedTokens[tokenGet] && whitelistedTokens[tokenGive]);

    // Sender should have at least the amount he wants to trade and 
    require(tokens[tokenGet][sender] >= amount);

    // order should have available volume to fill.
    return availableVolume(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, user, v, r, s) >= amount;
  }
// Solidity 0.4.24
/**
 * @dev Get the amount filled for the given order.
 * @param tokenGet   address
 * @param amountGet  uint256
 * @param tokenGive  address
 * @param amountGive uint256
 * @param expires    uint256
 * @param nonce      uint256
 * @param user       address
 * @return uint256
 */
function amountFilled(
    address tokenGet,
    uint256 amountGet,
    address tokenGive,
    uint256 amountGive,
    uint256 expires,
    uint256 nonce,
    address user
  )
    public
    constant
    returns (uint256)
  {
    // User should be whitelisted.
    require(whitelistedUsers[user]);

    // Tokens should be whitelisted.
    require(whitelistedTokens[tokenGet] && whitelistedTokens[tokenGive]);

    // Return the amount filled for the given order.
    return orderFills[user][keccak256(address(this), tokenGet, amountGet, tokenGive, amountGive, expires, nonce)];
  }
// Solidity 0.4.24
/**
 * @dev Trade balances of given tokens amounts between two users.
 * @param tokenGet   address
 * @param amountGet  uint256
 * @param tokenGive  address
 * @param amountGive uint256
 * @param user       address
 * @param amount     uint256
 */
function tradeBalances(
    address tokenGet,
    uint256 amountGet,
    address tokenGive,
    uint256 amountGive,
    address user,
    uint256 amount
  )
    private
  {
    // Calculate the constant taxes.
    uint256 feeMakeXfer = amount.mul(feeMake).div(1 ether);
    uint256 feeTakeXfer = amount.mul(feeTake).div(1 ether);
    uint256 feeRebateXfer = 0;
    
    // Calculate the tax according to account level.
    if (accountLevelsAddr != 0x0) {
      uint256 accountLevel = AccountLevels(accountLevelsAddr).accountLevel(user);
      if (accountLevel == 1) {
        feeRebateXfer = amount.mul(feeRebate).div(1 ether);
      } else if (accountLevel == 2) {
        feeRebateXfer = feeTakeXfer;
      }
    }

    // Update the balances for both maker and taker and add the fee to the feeAccount.
    tokens[tokenGet][msg.sender] = tokens[tokenGet][msg.sender].sub(amount.add(feeTakeXfer));
    tokens[tokenGet][user] = tokens[tokenGet][user].add(amount.add(feeRebateXfer).sub(feeMakeXfer));
    tokens[tokenGet][feeAccount] = tokens[tokenGet][feeAccount].add(feeMakeXfer.add(feeTakeXfer).sub(feeRebateXfer));
    tokens[tokenGive][user] = tokens[tokenGive][user].sub(amountGive.mul(amount).div(amountGet));
    tokens[tokenGive][msg.sender] = tokens[tokenGive][msg.sender].add(amountGive.mul(amount).div(amountGet));
  }
// Solidity 0.4.24
/**
 * @dev Validate an order hash.
 * @param hash bytes32
 * @param user address
 * @param v    uint8
 * @param r    bytes32
 * @param s    bytes32
 * @return bool
 */
function validateOrderHash(
    bytes32 hash,
    address user,
    uint8 v,
    bytes32 r,
    bytes32 s
  )
    private
    constant
    returns (bool)
  {
    return (
      orders[user][hash] ||
      ecrecover(keccak256("\x19Ethereum Signed Message:\n32", hash), v, r, s) == user
    );
  }
// Solidity 0.8.4
/**
 * @notice increase spend amount granted to spender
 * @param spender address whose allowance to increase
 * @param amount quantity by which to increase allowance
 * @return success status (always true; otherwise function will revert)
 */
function increaseAllowance (address spender, uint amount) virtual public returns (bool) {
    unchecked {
      mapping (address => uint) storage allowances = ERC20BaseStorage.layout().allowances[msg.sender];

      uint allowance = allowances[spender];
      require(allowance + amount >= allowance, 'ERC20Extended: excessive allowance');

      _approve(
        msg.sender,
        spender,
        allowances[spender] = allowance + amount
      );

      return true;
    }
  }
// Solidity 0.8.4
/**
 * @inheritdoc IERC20
 */
function transferFrom (
    address holder,
    address recipient,
    uint amount
  ) override virtual public returns (bool) {
    uint256 currentAllowance = ERC20BaseStorage.layout().allowances[holder][msg.sender];
    require(currentAllowance >= amount, 'ERC20: transfer amount exceeds allowance');
    unchecked {
      _approve(holder, msg.sender, currentAllowance - amount);
    }
    _transfer(holder, recipient, amount);
    return true;
  }
// Solidity 0.4.24
// @notice ContractManager will be the only contract that can add/remove contracts on the platform.
// @param (address) _contractManager is the contract which can upgrade/remove contracts to platform
function enableContractManagement(address _contractManager)
    external
    returns (bool){
        require(_contractManager != address(0), "Empty address");
        require(boolStorage[keccak256(abi.encodePacked("owner", msg.sender))], "Not owner");
        require(addressStorage[keccak256(abi.encodePacked("contract", "ContractManager"))] == address(0), "There is already a contract manager");
        addressStorage[keccak256(abi.encodePacked("contract", "ContractManager"))] = _contractManager;
        boolStorage[keccak256(abi.encodePacked("contract", _contractManager))] = true;
        return true;
    }