lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.4
/**
 * Get random index
 */
function randomIndex() internal returns (uint256) {
        uint256 totalSize = MAX_TOKENS - numTokens;
        uint256 index = uint256(
            keccak256(
                abi.encodePacked(
                    nonce,
                    msg.sender,
                    block.difficulty,
                    block.timestamp
                )
            )
        ) % totalSize;
        uint256 value = 0;
        if (indices[index] != 0) {
            value = indices[index];
        } else {
            value = index;
        }

        // Move last value to selected position
        if (indices[totalSize - 1] == 0) {
            // Array position not initialized, so use position
            indices[index] = totalSize - 1;
        } else {
            // Array position holds a value so use that
            indices[index] = indices[totalSize - 1];
        }
        nonce++;
        // Don't allow a zero index, start counting at 1
        return value.add(1);
    }
// Solidity 0.8.4
/**
 * Mint one token internal
 */
function _internalMint(address to) private returns (uint256) {
        require(numTokens < MAX_TOKENS, "Token limit");

        //Get random token
        uint256 id = randomIndex();

        //Change internal token amount
        numTokens++;

        //Mint token
        _mint(to, id);
        return id;
    }
// Solidity 0.8.4
/**
 * Mint selected amount of tokens
 */
function mint(address _to, uint8 _amount) public payable {
        require(mintEnabled, "Minting disabled");
        require(_amount <= 20, "Maximum 20 tokens per mint");
        require(msg.value >= _amount * tokenPrice, "Not enought money");
        require(_to != address(0), "Cannot mint to empty");

        _ensureDailyLimit(_amount);

        uint256 balance = msg.value;

        for (uint8 i = 0; i < _amount; i++) {
            // Sub user balance
            balance = balance.sub(tokenPrice);

            // Mint token tok user
            _internalMint(_to);
        }

        // Return not used balance
        payable(msg.sender).transfer(balance);
    }
// Solidity 0.8.4
/**
 * Mint selected amount of tokens to a given address by owner (airdrop)
 */
function airdrop(address _to, uint8 _amount) public onlyOwner {
        require(mintEnabled, "Minting disabled");
        require(_amount <= 20, "Maximum 20 tokens per mint");
        require(_to != address(0), "Cannot mint to empty");

        for (uint8 i = 0; i < _amount; i++) {
            // Mint token tok user
            _internalMint(_to);
        }
    }
// Solidity 0.8.9
/**
 * @dev Mints a token to an address with a tokenURI.
 * fee may or may not be required*
 * @param _to address of the future owner of the token
 */
function mintTo(address _to) public payable {
            require(_getNextTokenId() <= SUPPLYCAP, "Cannot mint over supply cap of 2");
            require(mintingOpen == true, "Minting is not open right now!");
            require(canMintAmount(_to, 1), "Wallet address is over the maximum allowed mints");
            
            
            uint256 newTokenId = _getNextTokenId();
            _mint(_to, newTokenId);
            _incrementTokenId();
            updateMintCount(_to, 1);
        }
// Solidity 0.6.12
// @notice Query if an address implements an interface and through which contract.
// @param _addr Address being queried for the implementer of an interface.
// (If '_addr' is the zero address then 'msg.sender' is assumed.)
// @param _interfaceHash Keccak256 hash of the name of the interface as a string.
// E.g., 'web3.utils.keccak256("ERC777TokensRecipient")' for the 'ERC777TokensRecipient' interface.
// @return The address of the contract which implements the interface '_interfaceHash' for '_addr'
// or '0' if '_addr' did not register an implementer for this interface.
function getInterfaceImplementer(address _addr, bytes32 _interfaceHash) external view override  returns (address) {
        address addr = _addr == address(0) ? msg.sender : _addr;
        if (isERC165Interface(_interfaceHash)) {
            bytes4 erc165InterfaceHash = bytes4(_interfaceHash);
            return implementsERC165Interface(addr, erc165InterfaceHash) ? addr : address(0);
        }
        return interfaces[addr][_interfaceHash];
    }
// Solidity 0.6.12
// @notice Sets the contract which implements a specific interface for an address.
// Only the manager defined for that address can set it.
// (Each address is the manager for itself until it sets a new manager.)
// @param _addr Address for which to set the interface.
// (If '_addr' is the zero address then 'msg.sender' is assumed.)
// @param _interfaceHash Keccak256 hash of the name of the interface as a string.
// E.g., 'web3.utils.keccak256("ERC777TokensRecipient")' for the 'ERC777TokensRecipient' interface.
// @param _implementer Contract address implementing '_interfaceHash' for '_addr'.
function setInterfaceImplementer(address _addr, bytes32 _interfaceHash, address _implementer) external override {
        address addr = _addr == address(0) ? msg.sender : _addr;
        require(getManager(addr) == msg.sender, "Not the manager");

        require(!isERC165Interface(_interfaceHash), "Must not be an ERC165 hash");
        if (_implementer != address(0) && _implementer != msg.sender) {
            require(
                IERC1820Implementer(_implementer)
                    .canImplementInterfaceForAddress(_interfaceHash, addr) == ERC1820_ACCEPT_MAGIC,
                "Does not implement the interface"
            );
        }
        interfaces[addr][_interfaceHash] = _implementer;
        emit InterfaceImplementerSet(addr, _interfaceHash, _implementer);
    }
// Solidity 0.6.12
// @notice Get the manager of an address.
// @param _addr Address for which to return the manager.
// @return Address of the manager for a given address.
function getManager(address _addr) public view override  returns(address) {
        // By default the manager of an address is the same address
        if (managers[_addr] == address(0)) {
            return _addr;
        } else {
            return managers[_addr];
        }
    }
// Solidity 0.6.12
// @notice Checks whether a contract implements an ERC165 interface or not without using nor updating the cache.
// @param _contract Address of the contract to check.
// @param _interfaceId ERC165 interface to check.
// @return True if '_contract' implements '_interfaceId', false otherwise.
function implementsERC165InterfaceNoCache(address _contract, bytes4 _interfaceId) public view override returns (bool) {
        uint256 success;
        uint256 result;

        (success, result) = noThrowCall(_contract, ERC165ID);
        if (success == 0 || result == 0) {
            return false;
        }

        (success, result) = noThrowCall(_contract, INVALID_ID);
        if (success == 0 || result != 0) {
            return false;
        }

        (success, result) = noThrowCall(_contract, _interfaceId);
        if (success == 1 && result == 1) {
            return true;
        }
        return false;
    }
// Solidity 0.6.12
// @dev Make a call on a contract without throwing if the function does not exist.
function noThrowCall(address _contract, bytes4 _interfaceId)
        internal view returns (uint256 success, uint256 result)
    {
        bytes4 erc165ID = ERC165ID;

        assembly {
            let x := mload(0x40)               // Find empty storage location using "free memory pointer"
            mstore(x, erc165ID)                // Place signature at beginning of empty storage
            mstore(add(x, 0x04), _interfaceId) // Place first argument directly next to signature

            success := staticcall(
                30000,                         // 30k gas
                _contract,                     // To addr
                x,                             // Inputs are stored at location x
                0x24,                          // Inputs are 36 (4 + 32) bytes long
                x,                             // Store output over input (saves space)
                0x20                           // Outputs are 32 bytes long
            )

            result := mload(x)                 // Load the result
        }
    }
// Solidity 0.8.10
// gets the amount of rew
function rewardPerToken(address _rewardToken)
        internal
        view
        returns (uint256 rewardPerToken_, uint256 lastTimeRewardApplicable_)
    {
        RewardToken storage rewardToken = s.rewardTokens[_rewardToken];
        uint256 l_totalSupply = s.totalSupply;
        uint256 lastUpdateTime = rewardToken.lastUpdateTime;
        lastTimeRewardApplicable_ = lastTimeRewardApplicable(_rewardToken);
        if (lastUpdateTime == 0 || l_totalSupply == 0) {
            rewardPerToken_ = rewardToken.rewardPerTokenStored;
        } else {
            rewardPerToken_ =
                rewardToken.rewardPerTokenStored +
                ((lastTimeRewardApplicable_ - lastUpdateTime) *
                    rewardToken.rewardRate *
                    1e18) /
                l_totalSupply;
        }
    }
// Solidity 0.6.12
/**
 * @dev Stake ERC-1155
 */
function stake(uint256[] calldata tokenIds, uint256[] calldata amounts) external nonReentrant whenNotPaused updateReward(msg.sender) {
        require(tokenIds.length == amounts.length, "TokenIds and amounts length should be the same");
        for(uint256 i = 0; i < tokenIds.length; i++) {
            stakeInternal(tokenIds[i], amounts[i]);
        }
    }
// Solidity 0.6.12
/**
 * @dev Stake particular ERC-1155 tokenId
 */
function stakeInternal(uint256 tokenId, uint256 amount) internal {
        (,,,,,uint256 series) = INodeRunnersNFT(address(NFT)).getFighter(tokenId);
        if(!nftTokenMap[tokenId].hasValue) {
            nftTokens.push(tokenId);
            nftTokenMap[tokenId] = NftToken({ hasValue: true });
        }
        require(supportedSeries[series] == true, "wrong id");
        require(nftTokenMap[tokenId].balances[msg.sender].add(amount) <= tokenMaxAmount, "NFT max reached");

        (uint256 strength,,,,,) = INodeRunnersNFT(address(NFT)).getFighter(tokenId);
        strength = strength.mul(amount);

        strengthWeight[msg.sender] = strengthWeight[msg.sender].add(strength);
        _totalStrength = _totalStrength.add(strength);
        _totalSupply = _totalSupply.add(amount);
        _balances[msg.sender] = _balances[msg.sender].add(amount);        
        nftTokenMap[tokenId].balances[msg.sender] = nftTokenMap[tokenId].balances[msg.sender].add(amount);

        NFT.safeTransferFrom(msg.sender, address(this), tokenId, amount, "0x0");
        emit Staked(msg.sender, tokenId, amount);
    }
// Solidity 0.6.12
/**
 * @dev Withdraw ERC-1155
 */
function withdrawNFT(uint256[] memory tokenIds, uint256[] memory amounts) public updateReward(msg.sender) {
        require(tokenIds.length == amounts.length, "TokenIds and amounts length should be the same");
        for(uint256 i = 0; i < tokenIds.length; i++) {
            withdrawNFTInternal(tokenIds[i], amounts[i]);
        }
    }
// Solidity 0.6.12
/**
 * @dev Withdraw particular ERC-1155 tokenId
 */
function withdrawNFTInternal(uint256 tokenId, uint256 amount) internal {
        (uint256 strength,,,,,) = INodeRunnersNFT(address(NFT)).getFighter(tokenId);
        strength = strength.mul(amount);

        strengthWeight[msg.sender] = strengthWeight[msg.sender].sub(strength);
        _totalStrength = _totalStrength.sub(strength);
        _totalSupply = _totalSupply.sub(amount);
        _balances[msg.sender] = _balances[msg.sender].sub(amount);
        nftTokenMap[tokenId].balances[msg.sender] = nftTokenMap[tokenId].balances[msg.sender].sub(amount);

        NFT.safeTransferFrom(address(this), msg.sender, tokenId, amount, "0x0");
        emit Withdrawn(msg.sender, tokenId, amount);
    }
// Solidity 0.6.12
/**
 * @dev Withdraw all cards
 */
function withdraw() public updateReward(msg.sender) {
        uint256[] memory tokenIds = new uint256[](nftTokens.length);
        uint256[] memory amounts = new uint256[](nftTokens.length);
        for (uint8 i = 0; i < nftTokens.length; i++) {
            uint256 tokenId = nftTokens[i];
            tokenIds[i] = tokenId;
            uint256 balance = nftTokenMap[tokenId].balances[msg.sender];
            amounts[i] = balance;
        }
        withdrawNFT(tokenIds, amounts);  
    }
// Solidity 0.8.3
/// @dev uADPriceReset remove uAD unilateraly from the curve LP share sitting inside
///      the bonding contract and send the uAD received to the treasury.
///      This will have the immediate effect of pushing the uAD price HIGHER
/// @param amount of LP token to be removed for uAD
/// @notice it will remove one coin only from the curve LP share sitting in the bonding contract
function uADPriceReset(uint256 amount) external onlyBondingManager {
        IMetaPool metaPool = IMetaPool(manager.stableSwapMetaPoolAddress());
        // safe approve
        IERC20(manager.stableSwapMetaPoolAddress()).safeApprove(
            address(this),
            amount
        );
        // remove one coin
        uint256 expected =
            (metaPool.calc_withdraw_one_coin(amount, 0) * 99) / 100;
        // update twap
        metaPool.remove_liquidity_one_coin(amount, 0, expected);
        ITWAPOracle(manager.twapOracleAddress()).update();
        IERC20(manager.dollarTokenAddress()).safeTransfer(
            manager.treasuryAddress(),
            IERC20(manager.dollarTokenAddress()).balanceOf(address(this))
        );
    }
// Solidity 0.8.3
/// @dev crvPriceReset remove 3CRV unilateraly from the curve LP share sitting inside
///      the bonding contract and send the 3CRV received to the treasury
///      This will have the immediate effect of pushing the uAD price LOWER
/// @param amount of LP token to be removed for 3CRV tokens
/// @notice it will remove one coin only from the curve LP share sitting in the bonding contract
function crvPriceReset(uint256 amount) external onlyBondingManager {
        IMetaPool metaPool = IMetaPool(manager.stableSwapMetaPoolAddress());
        // safe approve
        IERC20(manager.stableSwapMetaPoolAddress()).safeApprove(
            address(this),
            amount
        );
        // remove one coin
        uint256 expected =
            (metaPool.calc_withdraw_one_coin(amount, 1) * 99) / 100;
        // update twap
        metaPool.remove_liquidity_one_coin(amount, 1, expected);
        ITWAPOracle(manager.twapOracleAddress()).update();
        IERC20(manager.curve3PoolTokenAddress()).safeTransfer(
            manager.treasuryAddress(),
            IERC20(manager.curve3PoolTokenAddress()).balanceOf(address(this))
        );
    }
// Solidity 0.8.3
/// @dev deposit uAD-3CRV LP tokens for a duration to receive bonding shares
/// @param _lpsAmount of LP token to send
/// @param _weeks during lp token will be held
/// @notice weeks act as a multiplier for the amount of bonding shares to be received
function deposit(uint256 _lpsAmount, uint256 _weeks)
        public
        returns (uint256 _id)
    {
        require(
            1 <= _weeks && _weeks <= 208,
            "Bonding: duration must be between 1 and 208 weeks"
        );
        _updateOracle();

        IERC20(manager.stableSwapMetaPoolAddress()).safeTransferFrom(
            msg.sender,
            address(this),
            _lpsAmount
        );

        uint256 _sharesAmount =
            IUbiquityFormulas(manager.formulasAddress()).durationMultiply(
                _lpsAmount,
                _weeks,
                bondingDiscountMultiplier
            );

        // 1 week = 45361 blocks = 2371753*7/366
        // n = (block + duration * 45361)
        // id = n - n % blockRonding
        // blockRonding = 100 => 2 ending zeros
        uint256 n = block.number + _weeks * blockCountInAWeek;
        _id = n - (n % blockRonding);
        _mint(_sharesAmount, _id);
        // set masterchef for uGOV rewards
        IMasterChef(manager.masterChefAddress()).deposit(
            _sharesAmount,
            msg.sender
        );
    }
// Solidity 0.8.3
/// @dev withdraw an amount of uAD-3CRV LP tokens
/// @param _sharesAmount of bonding shares of type _id to be withdrawn
/// @param _id bonding shares id
/// @notice bonding shares are ERC1155 (aka NFT) because they have an expiration date
function withdraw(uint256 _sharesAmount, uint256 _id) public {
        require(
            block.number > _id,
            "Bonding: Redeem not allowed before bonding time"
        );

        require(
            IERC1155Ubiquity(manager.bondingShareAddress()).balanceOf(
                msg.sender,
                _id
            ) >= _sharesAmount,
            "Bonding: caller does not have enough shares"
        );

        _updateOracle();
        // get masterchef for uGOV rewards To ensure correct computation
        // it needs to be done BEFORE burning the shares
        IMasterChef(manager.masterChefAddress()).withdraw(
            _sharesAmount,
            msg.sender
        );

        uint256 _currentShareValue = currentShareValue();

        IERC1155Ubiquity(manager.bondingShareAddress()).burn(
            msg.sender,
            _id,
            _sharesAmount
        );

        // if (redeemStreamTime == 0) {
        IERC20(manager.stableSwapMetaPoolAddress()).safeTransfer(
            msg.sender,
            IUbiquityFormulas(manager.formulasAddress()).redeemBonds(
                _sharesAmount,
                _currentShareValue,
                ONE
            )
        );
    }
// Solidity 0.5.17
//Custom Minting Function for utility (to be called by trusted contracts)
function mintCustomWarrior(address owner, uint32 generation, bool special, uint randomSeed, uint16 colorHue, uint8 armorType, uint8 shieldType, uint8 weaponType) public onlyTrustedContracts returns(uint theNewWarrior) {
        //Calculate new Token ID for minting
        uint256 _id = _getNextTokenID();
        _incrementTokenTypeId();
        //Log the original creator of this warrior
        creators[_id] = owner;
		//Generate a new warrior metadata structure, and add it to the warriors array
        warriors[_id]=LibWarrior.newWarriorFixed(owner, generation, special, randomSeed, colorHue, armorType, shieldType, weaponType);
        //Mint the new token in the ledger
        _mint(owner, _id, 1, "");
        tokenSupply[_id] = 1;
		//Return new warrior index
        return _id;
	}
// Solidity 0.5.17
//Standard factory function, allowing minting warriors.
function newWarrior() public returns(uint theNewWarrior) {
        //Generate a new random seed for the warrior
        uint randomSeed = uint(blockhash(block.number - 1));    //YES WE KNOW this isn't truely random. it's predictable, and vulnerable to malicious miners... 
                                                                //Doesn't actually matter in this case. That's all ok. It's only for generating cosmetics etc...
        //Calculate the fee:
        uint warriorFee = LibWarrior.getWarriorCost();

        //Take fee from the owner
        transferFAME(msg.sender,address(this),warriorFee);

        //Calculate new Token ID for minting
        uint256 _id = _getNextTokenID();
        _incrementTokenTypeId();

        //Log the original creator of this warrior
        creators[_id] = msg.sender;

		//Generate a new warrior metadata structure, and add it to the warriors array
        warriors[_id]=LibWarrior.newWarrior(msg.sender, randomSeed);

		//Transfer the paid fee to the warrior as initial starting FAME
        FAMEToWarrior(_id,warriorFee,false);

        //Mint the new token in the ledger
        _mint(msg.sender, _id, 1, "");
        tokenSupply[_id] = 1;

		//Return new warrior index
        return _id;
	}
// Solidity 0.4.22
//// Secure payable fallback function - receives bets
function () external payable {
        require((msg.value == oneBet) || (msg.sender == owner));
        if (msg.sender != owner) {
            require(betsState && !emergencyBlock);
            require(!betsBlock);
            if (numberOfBets < participants+(extraBets-1)) {
                bets[numberOfBets] = msg.sender;
                numberOfBets++;
                emit GotBet(roundID, msg.sender, numberOfBets);
            } else {
                bets[numberOfBets] = msg.sender;
                numberOfBets++;
                emit GotBet(roundID, msg.sender, numberOfBets);
                betsState = false;
                emit ReadyToRoll(roundID, participants+extraBets, oneBet);
            }
        }
    }
// Solidity 0.4.22
//// Withdraw and distribute winnings
function withdrawWinnings() external payable
            onlyProxy
    {
        if ((msg.value > expectedReturn) && !emergencyBlock) {
            emit BetResult(roundID, 1, msg.value); // We won! Set 1
            distributeWinnings(msg.value);
        } else {
            emit BetResult(roundID, 0, msg.value); // We lost :( Set 0
        }
        
        numberOfBets = 0;
        betsState = true;
        roundID++;
    }
// Solidity 0.5.10
/**
 * @dev Allows the transfer of token amounts to multiple addresses
 * @param beneficiaries Array of addresses that receive the tokens
 * @param amounts Array of amounts to be transferred per beneficiary
 */
function multiTransfer(address[] calldata beneficiaries, uint256[] calldata amounts) external {
        uint256 length = beneficiaries.length;
        require(length == amounts.length, "lenghts are different");

        for (uint256 i = 0; i < length; i++) {
            super.transfer(beneficiaries[i], amounts[i]);
        }
    }
// Solidity 0.5.16
// ========== RESTRICTED ==========
function setCrossDomainMessageGasLimit(CrossDomainMessageGasLimits _gasLimitType, uint _crossDomainMessageGasLimit)
        external
        onlyOwner
    {
        require(
            _crossDomainMessageGasLimit >= MIN_CROSS_DOMAIN_GAS_LIMIT &&
                _crossDomainMessageGasLimit <= MAX_CROSS_DOMAIN_GAS_LIMIT,
            "Out of range xDomain gasLimit"
        );
        flexibleStorage().setUIntValue(
            SETTING_CONTRACT_NAME,
            _getGasLimitSetting(_gasLimitType),
            _crossDomainMessageGasLimit
        );
        emit CrossDomainMessageGasLimitChanged(_gasLimitType, _crossDomainMessageGasLimit);
    }
// Solidity 0.8.3
/**
 * @dev Returns the current implementation of `proxy`.
 *
 * Requirements:
 *
 * - This contract must be the admin of `proxy`.
 */
function getProxyImplementation(TransparentUpgradeableProxy proxy) public view virtual returns (address) {
        // We need to manually run the static call since the getter cannot be flagged as view
        // bytes4(keccak256("implementation()")) == 0x5c60da1b
        (bool success, bytes memory returndata) = address(proxy).staticcall(hex"5c60da1b");
        require(success);
        return abi.decode(returndata, (address));
    }
// Solidity 0.4.17
// Transfer the _amount from msg.sender to _to account
function transfer(address _to, uint256 _amount) public returns (bool) {
        if (balances[msg.sender] >= _amount && _amount > 0
                && balances[_to] + _amount > balances[_to]) {
            balances[msg.sender] -= _amount;
            balances[_to] += _amount;
            Transfer(msg.sender, _to, _amount);
            return true;
        } else {
            return false;
        }
    }
// Solidity 0.4.17
// fallback function, Charon sells napkins as merchandise!
function () public payable {
        uint256 amount;
        uint256 checkedAmount;
        // give away some napkins in return proportional to value
        amount = msg.value / napkinPrice;
        checkedAmount = checkAmount(amount);
        // only payout napkins if there is the appropriate amount available
        // else throw
        require(amount == checkedAmount);
        // forward money to Charon
        payCharon(msg.value);
        // finally payout napkins
        payOutNapkins(checkedAmount);
    }