lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
// For wallet Angel Sales and PE Sales
function getWithdrawableAmountANPES(address _investor) public view returns(uint256) {
        require(startWithdraw != 0);
        // interval in months
        uint interval = safeDiv(safeSub(now,startWithdraw),30 days);
        // total allocatedTokens
        uint _allocatedTokens = safeAdd(walletAngelPESales[_investor],releasedAngelPESales[_investor]);
        // Atleast 6 months
        if (interval < 6) { 
            return (0); 
        } else if (interval >= 6 && interval < 12) {
            return safeSub(getPercentageAmount(25,_allocatedTokens), releasedAngelPESales[_investor]);
        } else if (interval >= 12 && interval < 18) {
            return safeSub(getPercentageAmount(50,_allocatedTokens), releasedAngelPESales[_investor]);
        } else if (interval >= 18 && interval < 24) {
            return safeSub(getPercentageAmount(75,_allocatedTokens), releasedAngelPESales[_investor]);
        } else if (interval >= 24) {
            return safeSub(_allocatedTokens, releasedAngelPESales[_investor]);
        }
    }
// Solidity 0.4.24
// For wallet Founding Investor and Initiator Team
function getWithdrawableAmountFIIT(address _investor) public view returns(uint256) {
        require(startWithdraw != 0);
        // interval in months
        uint interval = safeDiv(safeSub(now,startWithdraw),30 days);
        // total allocatedTokens
        uint _allocatedTokens = safeAdd(walletFoundingInitiatorSales[_investor],releasedFoundingInitiatorSales[_investor]);
        // Atleast 24 months
        if (interval < 24) { 
            return (0); 
        } else if (interval >= 24) {
            return safeSub(_allocatedTokens, releasedFoundingInitiatorSales[_investor]);
        }
    }
// Solidity 0.4.24
// Sale of the tokens. Investors can call this method to invest into ITT Tokens
function() payable external {
        // Allow only to invest in ICO stage
        require(startStop);

        //Sorry !! We only allow to invest with minimum 0.5 Ether as value
        require(msg.value >= (0.5 ether));

        // multiply by exchange rate to get token amount
        uint256 calculatedTokens = safeMul(msg.value, tokensPerEther);

        // Wait we check tokens available for assign
        require(balances[ethExchangeWallet] >= calculatedTokens);

        // Call to Internal function to assign tokens
        assignTokens(msg.sender, calculatedTokens);
    }
// Solidity 0.4.24
// Function will transfer the tokens to investor's address
// Common function code for assigning tokens
function assignTokens(address investor, uint256 tokens) internal {
        // Debit tokens from ether exchange wallet
        balances[ethExchangeWallet] = safeSub(balances[ethExchangeWallet], tokens);

        // Assign tokens to the sender
        balances[investor] = safeAdd(balances[investor], tokens);

        // Finally token assigned to sender, log the creation event
        Transfer(ethExchangeWallet, investor, tokens);
    }
// Solidity 0.4.24
//  Transfer `value` ITTokens from sender's account
// `msg.sender` to provided account address `to`.
// @param _to The address of the recipient
// @param _value The number of ITTokens to transfer
// @return Whether the transfer was successful or not
function transfer(address _to, uint _value) public returns (bool ok) {
        //validate receiver address and value.Not allow 0 value
        require(_to != 0 && _value > 0);
        uint256 senderBalance = balances[msg.sender];
        //Check sender have enough balance
        require(senderBalance >= _value);
        senderBalance = safeSub(senderBalance, _value);
        balances[msg.sender] = senderBalance;
        balances[_to] = safeAdd(balances[_to], _value);
        Transfer(msg.sender, _to, _value);
        return true;
    }
// Solidity 0.5.12
/**
 * @dev Creates a new token type and assigns _initialSupply to an address
 * NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
 * @param _initialOwner address of the first owner of the token
 * @param _initialSupply amount to supply the first owner
 * @param _uri Optional URI for this token type
 * @param _data Data to pass if receiver is contract
 * @return The newly created token ID
 */
function create(
    address _initialOwner,
    uint256 _initialSupply,
    string calldata _uri,
    bytes calldata _data
  ) external onlyOwner returns (uint256) {

    uint256 _id = _getNextTokenID();
    _incrementTokenTypeId();
    creators[_id] = msg.sender;

    if (bytes(_uri).length > 0) {
      emit URI(_uri, _id);
    }

    _mint(_initialOwner, _id, _initialSupply, _data);
    tokenSupply[_id] = _initialSupply;
    return _id;
  }
// Solidity 0.5.12
/**
 * @dev Mint tokens for each id in _ids
 * @param _to          The address to mint tokens to
 * @param _ids         Array of ids to mint
 * @param _quantities  Array of amounts of tokens to mint per id
 * @param _data        Data to pass if receiver is contract
 */
function batchMint(
    address _to,
    uint256[] memory _ids,
    uint256[] memory _quantities,
    bytes memory _data
  ) public {
    for (uint256 i = 0; i < _ids.length; i++) {
      uint256 _id = _ids[i];
      require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
      uint256 quantity = _quantities[i];
      tokenSupply[_id] += quantity;
    }
    _batchMint(_to, _ids, _quantities, _data);
  }
// Solidity 0.5.12
/**
 * Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
 */
function isApprovedForAll(
    address _owner,
    address _operator
  ) public view returns (bool isOperator) {
    // Whitelist OpenSea proxy contract for easy trading.
    ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
    if (address(proxyRegistry.proxies(_owner)) == _operator) {
      return true;
    }

    return ERC1155.isApprovedForAll(_owner, _operator);
  }
// Solidity 0.4.21
// if accidentally other token was donated to Project Dev
function sendTokenAw(address StandardTokenAddress, address receiver, uint amount){
		if (msg.sender != honestisFort) {
		throw;
		}
		sendTokenAway t = transfers[numTransfers];
		t.coinContract = StandardToken(StandardTokenAddress);
		t.amount = amount;
		t.recipient = receiver;
		t.coinContract.transfer(receiver, amount);
		numTransfers++;
	}
// Solidity 0.8.11
// removed isValidData(_data) modifier since this function is also called from SentEnoughEther modifier
// _data is checked in parent functions!  not checked here!
function getPrice(
    MintData memory _data
  )
    public
    view
    returns (uint256)
  {
    uint256 price = 0;
    uint8 _tokenStyle = _data.tokenStyle;

    // there is a discount to the first DISCOUNT_MINT_MAX STYLE_JAWS mints during WhitelistSale
    //   this check intentionally allows a single overbuy at the end of discounted sale. Without this,
    //   we would require a permint mint quantity to proceed with undiscounted minted. This could
    //   be solved with additional complexity, but a couple extra discounted tokens to enable
    //   a smooth minting experience is a worthwhile tradeoff
    if( 
        ( saleState == State.WhitelistSale ) &&  
        ( _tokenStyle == STYLE_JAWS ) &&
        ( mintStyle[_tokenStyle].sold < DISCOUNT_MINT_MAX ) // allow a single overbuy at end of discounted sale
      )
    {
      price = mintStyle[_tokenStyle].price - DISCOUNT;
    }
    else
    {
      price = mintStyle[_tokenStyle].price;
    }
    return price;
  }
// Solidity 0.8.7
//
// Does state updates at mint time and on every transfer
//
function updateVoyagerState(address to, uint256 cvMintIndex) private {
        uint256 n_tokens = 0;
        if (!_test_chain_mode) {
            // Query any n's we hold
            n_tokens = n.balanceOf(to);
        }
        uint256 new_voyage_count = voyage_count[cvMintIndex] + 1;

        string memory trunc_addr = addrToString(to, 3);

        // Track in the circular ring buffer
        if (new_voyage_count <= MAX_ADDRESS_HISTORY) {
            address_history[cvMintIndex].push(trunc_addr);
        } else {
            uint256 write_idx = new_voyage_count % MAX_ADDRESS_HISTORY;
            address_history[cvMintIndex][write_idx] = trunc_addr;
        }

        // Accumulate totals of the N's taking the firs token we find
        if (n_tokens > 0) {
            uint256 n_id = (n.tokenOfOwnerByIndex(to, 0));
            uint256 n_first = n.getFirst(n_id);
            n_sum_first[cvMintIndex] += n_first;
        }

        voyage_count[cvMintIndex] = new_voyage_count;
    }
// Solidity 0.5.17
/**
 * @notice Approve `spender` to transfer up to `amount` from `src`
 * @dev This will overwrite the approval amount for `spender`
 *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
 * @param spender The address of the account which may transfer tokens
 * @param rawAmount The number of tokens that are approved (2^256-1 means infinite)
 * @return Whether or not the approval succeeded
 */
function approve(address spender, uint rawAmount) external returns (bool) {
        uint96 amount;
        if (rawAmount == uint(-1)) {
            amount = uint96(-1);
        } else {
            amount = safe96(rawAmount, "Comfi::approve: amount exceeds 96 bits");
        }

        allowances[msg.sender][spender] = amount;

        emit Approval(msg.sender, spender, amount);
        return true;
    }
// Solidity 0.5.17
/**
 * @notice Triggers an approval from owner to spends
 * @param owner The address to approve from
 * @param spender The address to be approved
 * @param rawAmount The number of tokens that are approved (2^256-1 means infinite)
 * @param deadline The time at which to expire the signature
 * @param v The recovery byte of the signature
 * @param r Half of the ECDSA signature pair
 * @param s Half of the ECDSA signature pair
 */
function permit(address owner, address spender, uint rawAmount, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
        uint96 amount;
        if (rawAmount == uint(-1)) {
            amount = uint96(-1);
        } else {
            amount = safe96(rawAmount, "Comfi::permit: amount exceeds 96 bits");
        }

        bytes32 domainSeparator = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainId(), address(this)));
        bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, rawAmount, nonces[owner]++, deadline));
        bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
        address signatory = ecrecover(digest, v, r, s);
        require(signatory != address(0), "Comfi::permit: invalid signature");
        require(signatory == owner, "Comfi::permit: unauthorized");
        require(now <= deadline, "Comfi::permit: signature expired");

        allowances[owner][spender] = amount;

        emit Approval(owner, spender, amount);
    }
// Solidity 0.5.17
/**
 * @notice Transfer `amount` tokens from `src` to `dst`
 * @param src The address of the source account
 * @param dst The address of the destination account
 * @param rawAmount The number of tokens to transfer
 * @return Whether or not the transfer succeeded
 */
function transferFrom(address src, address dst, uint rawAmount) external returns (bool) {
        address spender = msg.sender;
        uint96 spenderAllowance = allowances[src][spender];
        uint96 amount = safe96(rawAmount, "Comfi::approve: amount exceeds 96 bits");

        if (spender != src && spenderAllowance != uint96(-1)) {
            uint96 newAllowance = sub96(spenderAllowance, amount, "Comfi::transferFrom: transfer amount exceeds spender allowance");
            allowances[src][spender] = newAllowance;

            emit Approval(src, spender, newAllowance);
        }

        _transferTokens(src, dst, amount);
        return true;
    }
// Solidity 0.8.7
// RZ Mint Slots
function availableRZMintSlots() public view returns (uint256) {

        uint256 availableMintSlots = 0;
        if (ribonzContract.balanceOf(msg.sender) == 0) {
            // If not holding RIBONZ genesis can't get an RZ mint slot
            return 0;
        }

        uint256[] memory stTokensOfOwner = spacetimeContract.tokensOfOwner(msg.sender);

        
        for (uint256 i= 0; i<stTokensOfOwner.length; i++) {
            if (spaceTimeMintSlots[stTokensOfOwner[i]] == 0) {
                availableMintSlots++;
            }
        }
        
        return availableMintSlots;
    }
// Solidity 0.8.7
//
// Mint a voygagerz with special promo for RIBONZ Genesis  + Spacetime holders
//
function mintVoyagerzWithRZ(uint256 num_to_mint) public payable virtual nonReentrant {
        // Precondition checks here
        uint256 availableSlots = availableRZMintSlots();

        
        require(availableSlots >= num_to_mint, "Need to hold RIBONZ: Genesis and more RIBONZ: Spacetime than mint count");
        console.log('RZ MINT SLOTS', availableSlots);

        // Each special offer mint 'consumes' a spacetime special offer slot
        uint256[] memory stTokensOfOwner = spacetimeContract.tokensOfOwner(msg.sender);
        

        // Do the mint at discount price!
        mintVoyagerzInternal(num_to_mint, mintPriceSpecialOfferForRZHolders);

        uint256 mintSlotsToConsume = num_to_mint;

        //
        // Consume the mint slots
        //
        for (uint256 i= 0; i<stTokensOfOwner.length; i++) {
            // Eat up a slot 
            if (mintSlotsToConsume > 0 && (spaceTimeMintSlots[stTokensOfOwner[i]] == 0)) {
                spaceTimeMintSlots[stTokensOfOwner[i]] = 1;
                mintSlotsToConsume--;
                console.log('ST Mint Slot CONSUME', stTokensOfOwner[i]);
            }
        }
    }
// Solidity 0.8.0
/**
 * @dev Returns true if `account` is a contract.
 *
 * [IMPORTANT]
 * ====
 * It is unsafe to assume that an address for which this function returns
 * false is an externally-owned account (EOA) and not a contract.
 *
 * Among others, `isContract` will return false for the following
 * types of addresses:
 *
 *  - an externally-owned account
 *  - a contract in construction
 *  - an address where a contract will be created
 *  - an address where a contract lived, but was destroyed
 * ====
 *
 * [IMPORTANT]
 * ====
 * You shouldn't rely on `isContract` to protect against flash loan attacks!
 *
 * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
 * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
 * constructor.
 * ====
 */
function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }
// Solidity 0.5.16
/**
 * @dev 1. Mints an mAsset and then deposits to SAVE
 * @param _bAsset       bAsset address
 * @param _amt          Amount of bAsset to mint with
 * @param _stake        Add the imUSD to the Savings Vault?
 */
function saveViaMint(address _bAsset, uint256 _amt, bool _stake) external {
        // 1. Get the input bAsset
        IERC20(_bAsset).transferFrom(msg.sender, address(this), _amt);
        // 2. Mint
        IMasset mAsset_ = IMasset(mAsset);
        uint256 massetsMinted = mAsset_.mint(_bAsset, _amt);
        // 3. Mint imUSD and optionally stake in vault
        _saveAndStake(massetsMinted, _stake);
    }
// Solidity 0.5.16
/**
 * @dev 2. Buys mUSD on Curve, mints imUSD and optionally deposits to the vault
 * @param _input         bAsset to sell
 * @param _curvePosition Index of the bAsset in the Curve pool
 * @param _minOutCrv     Min amount of mUSD to receive
 * @param _amountIn      Input asset amount
 * @param _stake         Add the imUSD to the Savings Vault?
 */
function saveViaCurve(
        address _input,
        int128 _curvePosition,
        uint256 _amountIn,
        uint256 _minOutCrv,
        bool _stake
    ) external {
        // 1. Get the input asset
        IERC20(_input).transferFrom(msg.sender, address(this), _amountIn);
        // 2. Purchase mUSD
        uint256 purchased = curve.exchange_underlying(_curvePosition, 0, _amountIn, _minOutCrv);
        // 3. Mint imUSD and optionally stake in vault
        _saveAndStake(purchased, _stake);
    }
// Solidity 0.5.16
/**
 * @dev 3. Buys a bAsset on Uniswap with ETH then mUSD on Curve
 * @param _amountOutMin  bAsset to sell
 * @param _path          Sell path on Uniswap (e.g. [WETH, DAI])
 * @param _curvePosition Index of the bAsset in the Curve pool
 * @param _minOutCrv     Min amount of mUSD to receive
 * @param _stake         Add the imUSD to the Savings Vault?
 */
function saveViaUniswapETH(
        uint256 _amountOutMin,
        address[] calldata _path,
        int128 _curvePosition,
        uint256 _minOutCrv,
        bool _stake
    ) external payable {
        // 1. Get the bAsset
        uint[] memory amounts = uniswap.swapExactETHForTokens.value(msg.value)(
            _amountOutMin,
            _path,
            address(this),
            now + 1000
        );
        // 2. Purchase mUSD
        uint256 purchased = curve.exchange_underlying(_curvePosition, 0, amounts[amounts.length-1], _minOutCrv);
        // 3. Mint imUSD and optionally stake in vault
        _saveAndStake(purchased, _stake);
    }
// Solidity 0.5.12
/**
 * @notice Transfers amount amount of an _id from the _from address to the _to address specified
 * @param _from    Source address
 * @param _to      Target address
 * @param _id      ID of the token type
 * @param _amount  Transfered amount
 * @param _data    Additional data with no specified format, sent in call to `_to`
 */
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
    public
  {
    require((msg.sender == _from) || operators[_from][msg.sender], "ERC1155#safeTransferFrom: INVALID_OPERATOR");
    require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
    // require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations

    _safeTransferFrom(_from, _to, _id, _amount);
    _callonERC1155Received(_from, _to, _id, _amount, _data);
  }
// Solidity 0.5.12
/**
 * @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
 * @param _from     Source addresses
 * @param _to       Target addresses
 * @param _ids      IDs of each token type
 * @param _amounts  Transfer amounts per token type
 * @param _data     Additional data with no specified format, sent in call to `_to`
 */
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
    public
  {
    // Requirements
    require((msg.sender == _from) || operators[_from][msg.sender], "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
    require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");

    _safeBatchTransferFrom(_from, _to, _ids, _amounts);
    _callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
  }
// Solidity 0.5.12
/**
 * @notice Transfers amount amount of an _id from the _from address to the _to address specified
 * @param _from    Source address
 * @param _to      Target address
 * @param _id      ID of the token type
 * @param _amount  Transfered amount
 */
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
    internal
  {
    // Update balances
    balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
    balances[_to][_id] = balances[_to][_id].add(_amount);     // Add amount

    // Emit event
    emit TransferSingle(msg.sender, _from, _to, _id, _amount);
  }
// Solidity 0.5.12
/**
 * @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
 */
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
    internal
  {
    // Check if recipient is contract
    if (_to.isContract()) {
      bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
      require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
    }
  }
// Solidity 0.8.1
/**
 * @dev Minting for whitelisted addresses
 *
 * Requirements:
 * 
 * Contract must be unpaused
 * The presale must be going on
 * The caller must request less than the max by address authorized
 * The amount of token must be superior to 0
 * The supply must not be empty
 * The price must be correct
 * 
 * @param amountToMint the number of token to mint
 * @param merkleProof for the wallet address 
 * 
 */
function whitlistedMinting (uint amountToMint, bytes32[] calldata merkleProof ) external payable isWhitelisted(merkleProof) {
        require (!_paused, "Contract paused");
        require (_presale, "Presale over!");
        require (amountToMint + balanceOf(msg.sender) <= _maxNftByWallet, "Requet too much for a wallet"); 
        require (amountToMint > 0, "Error in the amount requested");
        require (amountToMint + totalSupply() <= _maxSupply - _reserved, "Request superior max Supply");
        require (msg.value >= _price*amountToMint, "Insuficient funds");
        _mintNFT(amountToMint);        
    }
// Solidity 0.8.1
/**
 * @dev Minting for the public sale
 *
 * Requirements:
 * 
 * The presale must be over
 * The caller must request less than the max by address authorized
 * The amount of token must be superior to 0
 * The supply must not be empty
 * The price must be correct
 * 
 * @param amountToMint the number of token to mint
 * 
 */
function publicMint(uint amountToMint) external payable{
        require (!_paused, "Contract paused"); 
        require (!_presale, "Presale on");
        require (amountToMint + balanceOf(msg.sender) <= _maxNftByWallet, "Requet too much for a wallet"); 
        require (amountToMint > 0, "Error in the amount requested");
        require (amountToMint + totalSupply() <= _maxSupply - _reserved, "Request superior max Supply");
        require (msg.value >= _price*amountToMint, "Insuficient funds");
        _mintNFT(amountToMint);        
    }
// Solidity 0.5.12
/**
 * @notice Get the balance of multiple account/token pairs
 * @param _owners The addresses of the token holders
 * @param _ids    ID of the Tokens
 * @return        The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
 */
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
    public view returns (uint256[] memory)
  {
    require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");

    // Variables
    uint256[] memory batchBalances = new uint256[](_owners.length);

    // Iterate over each owner and token ID
    for (uint256 i = 0; i < _owners.length; i++) {
      batchBalances[i] = balances[_owners[i]][_ids[i]];
    }

    return batchBalances;
  }