lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @dev Internal function to update the implementation of a specific proxied component of the protocol
 * - If there is no proxy registered in the given `id`, it creates the proxy setting `newAdress`
 *   as implementation and calls the initialize() function on the proxy
 * - If there is already a proxy registered, it just updates the implementation to `newAddress` and
 *   calls the initialize() function via upgradeToAndCall() in the proxy
 * @param id The id of the proxy to be updated
 * @param newAddress The address of the new implementation
 **/
function _updateImpl(bytes32 id, address newAddress) internal {
    address payable proxyAddress = payable(_addresses[id]);

    InitializableImmutableAdminUpgradeabilityProxy proxy =
      InitializableImmutableAdminUpgradeabilityProxy(proxyAddress);
    bytes memory params = abi.encodeWithSignature('initialize(address)', address(this));

    if (proxyAddress == address(0)) {
      proxy = new InitializableImmutableAdminUpgradeabilityProxy(address(this));
      proxy.initialize(newAddress, params);
      _addresses[id] = address(proxy);
      emit ProxyCreated(id, address(proxy));
    } else {
      proxy.upgradeToAndCall(newAddress, params);
    }
  }
// Solidity 0.6.12
/// @dev Set all the basic parameters. Must only be called by the owner.
/// @param _priceFeed The new address of Price Oracle.
/// @param _pair The new pair address.
/// @param _company The new company address.
/// @param _activateReward The new reward value in USD given to activator.
/// @param _harvestFee The new harvest fee rate given to company.
/// @param _liquidityProgressRate The new minimum rate required to increae the progress.
/// @param _payAmount The new amount to be paid on entry.
/// @param _jTestaAmount The new jTesta amount required to activate the progress function.
function setParem(
        address _priceFeed,
        address _pair,
        address _company,
        uint256 _activateReward,
        uint256 _harvestFee,
        uint256 _liquidityProgressRate,
        uint256 _payAmount,
        uint256 _jTestaAmount,
        uint256 _activateAtBlock,
        int _minProgressive,
        int _maxProgressive
    ) public onlyOwner {
        priceFeed = AggregatorV3Interface(_priceFeed);
        pair = IUniswapV2Pair(_pair);
        company = _company;
        activateReward = _activateReward;
        harvestFee = _harvestFee;
        liquidityProgressRate = _liquidityProgressRate;
        payAmount = _payAmount;
        jTestaAmount = _jTestaAmount;
        activateAtBlock = _activateAtBlock;
        minProgressive = _minProgressive;
        maxProgressive = _maxProgressive;
    }
// Solidity 0.6.12
/// @dev Return the latest price for ETH-USD.
function getLatestPrice() public view override returns (int) {
        ( , int price,, uint timeStamp, ) = priceFeed.latestRoundData();
        // If the round is not complete yet, timestamp is 0
        require(timeStamp > 0, "Round not complete");
        return price;
    }
// Solidity 0.6.12
/// @dev Return the amount of Testa wei rewarded if we are activate the progress function.
function getTestaReward() public view override returns (uint256) {
        ( uint112 _reserve0, uint112 _reserve1, ) = pair.getReserves();
        uint256 reserve = uint256(_reserve0).mul(1e18).div(uint256(_reserve1));
        uint256 ethPerDollar = uint256(getLatestPrice()).mul(1e10); // 1e8
        uint256 testaPerDollar = ethPerDollar.mul(1e18).div(reserve);
        
        uint256 _activateReward = activateReward.mul(1e18);
        uint256 testaAmount = _activateReward.mul(1e18).div(testaPerDollar);
        return testaAmount;
    }
// Solidity 0.6.12
/// @dev Return the amount of Testa wei to spend upon harvesting reward.
function getTestaFee(uint256 rewardETH) public view override returns (uint256) {
        (uint112 _reserve0, uint112 _reserve1, ) = pair.getReserves();
        uint256 reserve = uint256(_reserve0).mul(1e18).div(uint256(_reserve1));
        uint256 ethPerDollar = uint256(getLatestPrice()).mul(1e10); // 1e8
        uint256 testaPerDollar = ethPerDollar.mul(1e18).div(reserve);
        
        uint256 ethFee = harvestFee.mul(rewardETH).div(10000).mul(ethPerDollar);
        uint256 testaFee = ethFee.mul(1e18).div(testaPerDollar).div(1e18);
        return testaFee;
    }
// Solidity 0.4.25
// Not entirely trustless but seems only way
function refundTokenPurchase(uint256 clanId, uint256 tokensAmount, uint256 reimbursement) external {
        require(msg.sender == owner);
        require(tokensAmount > 0);
        require(clans.exists(clanId));
        
        // Transfer tokens
        address tokenAddress = clans.clanToken(clanId);
        require(ERC20(tokenAddress).transferFrom(owner, address(clans), tokensAmount));
        
        // Reimburse purchaser
        require(reimbursement >= tokenPurchaseAllocation);
        tokenPurchaseAllocation -= reimbursement;
        owner.transfer(reimbursement);
        
        // Auditable log
        emit TokenPurchase(tokenAddress, tokensAmount, reimbursement);
    }
// Solidity 0.6.12
/**
 * @dev receive random number from chainlink
 * @notice random number will greater than zero
 */
function fulfillRandomness(bytes32 requestId, uint256 randomNumber)
        internal
        override
    {
        require(_requesting == true, "not requesting");
        require(requestId == _requestId, "not my request");
        _requesting = false;
        if (randomNumber > 0) seed = randomNumber;
        else seed = 1;
        emit TokenSeed(seed);
    }
// Solidity 0.6.12
/**
 * @dev query tokenURI of token Id
 * @dev before reveal will return default URI
 * @dev after reveal return token URI of this token on IPFS
 * @param tokenId The id of token you want to query
 */
function uri(uint256 tokenId)
        external
        view
        virtual
        override
        returns (string memory)
    {
        require(tokenId < nextIndex(), "URI query for nonexistant token");

        // before reveal, nobody know what happened. Return _blankURI
        if (seed == 0) {
            return blankURI;
        }

        // after reveal, you can know your know.
        return
            string(abi.encodePacked(baseMetadataURI, deterministic(tokenId)));
    }
// Solidity 0.6.12
/**
 * @dev Airdrop ether to a list of address
 * @param _to List of address
 * @param _value List of value
 */
function multiAirdrop(address[] calldata _to, uint256[] calldata _value)
        public
        onlyOwner
        returns (bool _success)
    {
        // input validation
        assert(_to.length == _value.length);
        assert(_to.length <= 255);

        // loop through to addresses and send value
        for (uint8 i = 0; i < _to.length; i++) {
            payable(_to[i]).transfer(_value[i]);
        }

        return true;
    }
// Solidity 0.4.19
/**
 * the rate (how much tokens are given for 1 ether)
 * is calculated according to presale/sale period and the amount of ether
 */
function getRate() internal view returns (uint256) {
        uint256 calcRate = rate;
        //check if this sale is in presale period
        if (validPresalePurchase()) {
            calcRate = basicPresaleRate;
        }
        else {
            //if not validPresalePurchase() and not validPurchase() this function is not called
            // so no need to check validPurchase() again here
            uint256 daysPassed = (now - startTime) / 1 days;
            if (daysPassed < 15) {
                calcRate = 100 + (15 - daysPassed);
            }
        }
        calcRate = calcRate.mul(etherRate);
        return calcRate;
    }
// Solidity 0.4.19
// @return true if the transaction can buy tokens in presale
function validPresalePurchase() internal constant returns (bool) {
        bool withinPeriod = now >= presaleStartTime && now <= presaleEndTime;
        bool nonZeroPurchase = msg.value != 0;
        bool validPresaleLimit = msg.value >= presaleLimit;
        return withinPeriod && nonZeroPurchase && validPresaleLimit;
    }
// Solidity 0.8.9
/*
 * @dev Returns URI for the {_tokenId} passed as parameter to the function.
 */
function uri(uint256 _tokenId)
        public
        view
        override
        returns (string memory)
    {
        uint256 id = _tokenId;
        bytes memory reversed = new bytes(100);
        uint256 i = 0;
        while (id != 0) {
            reversed[i++] = bytes1(
                uint8((id % 10) + 48)
            );
            id /= 10;
        }

        bytes memory ordered = new bytes(i);
        for (uint256 j = 0; j < i; j++) {
            ordered[j] = reversed[i - j - 1];
        }

        return string(
            abi.encodePacked(
                super.uri(_tokenId),
                string(ordered),
                ".json"
            )
        );
    }
// Solidity 0.7.4
// Swaps OHM for DAI, then mints new OHM and sends to distributor
// uint _triggerDistributor - triggers staking distributor if == 1
function makeSale( uint _triggerDistributor ) external returns ( bool ) {
        require( salesEnabled, "Sales are not enabled" );
        require( block.number >= nextEpochBlock, "Not next epoch" );

        IERC20(OHM).approve( SUSHISWAP_ROUTER_ADDRESS, OHMToSell );
        sushiswapRouter.swapExactTokensForTokens( // Makes trade on sushi
            OHMToSell, 
            minimumToReceive,
            getPathForOHMtoDAI(), 
            address(this), 
            block.timestamp + 15
        );
        
        uint daiBalance = IERC20(DAI).balanceOf(address(this) );
        IERC20( DAI ).approve( vault, daiBalance );
        IVault( vault ).depositReserves( daiBalance ); // Mint OHM

        uint OHMToTransfer = IERC20(OHM).balanceOf( address(this) ).sub( OHMToSellNextEpoch );
        uint transferToDAO = OHMToTransfer.div( DAOShare );

        IERC20(OHM).transfer( stakingDistributor, OHMToTransfer.sub( transferToDAO ) ); // Transfer to staking
        IERC20(OHM).transfer( DAO, transferToDAO ); // Transfer to DAO

        nextEpochBlock = nextEpochBlock.add( epochBlockLength );
        OHMToSell = OHMToSellNextEpoch;

        if ( _triggerDistributor == 1 ) { 
            StakingDistributor( stakingDistributor ).distribute(); // Distribute epoch rebase
        }
        return true;
    }
// Solidity 0.8.10
/// @notice Mint new NFT
/// @dev Anyone can call this function
function mint(uint256 amount) external payable {
        require(totalSupply + amount <= MAX_SUPPLY, "!OOS"); // Out of stock

        if (totalSupply + amount <= 800) {
            require(amount == 1, "!IA"); // Invalid amount
        } else {
            require(amount > 0 && amount <= 20, "!IA");
            require(msg.value >= MINT_PRICE * amount, "!NEETH"); // Not enough ETH
        }

        for (uint256 i = 0; i < amount; i++) {
            // Mint user the NFT token
            uint256 tokenID = totalSupply + 1;
            _mint(msg.sender, tokenID);
            // Update total supply
            totalSupply = tokenID;
        }
    }
// Solidity 0.8.10
/// @notice Mint new NFT to given address
/// @notice This is free mint
/// @dev only owner can call this function
function mintTo(address recipient, uint256 amount) external onlyOwner {
        require(totalSupply >= 801, "!SNV"); // Supply not valid
        require(totalSupply + amount <= MAX_SUPPLY, "!OOS"); // Out of stock

        for (uint256 i = 0; i < amount; i++) {
            // Mint user the NFT token
            uint256 tokenID = totalSupply + 1;
            _mint(recipient, tokenID);
            totalSupply = tokenID;
        }
    }
// Solidity 0.8.10
/// @notice Send ETH inside the contract to multisig address
function withdraw() external {
        // Split amount
        (uint256 ten, uint256 ninety) = splitFee(address(this).balance);
        (bool success, ) = address(FEE_RECIPIENT_90).call{ value: ninety }("");
        require(success, "!FWF");
        (success, ) = address(FEE_RECIPIENT_10).call{ value: ten }("");
        require(success, "!SWF");
    }
// Solidity 0.5.16
/**
 * @dev Transfer token for a specified address
 * @param _token erc20 The address of the ERC20 contract
 * @param _to address The address which you want to transfer to
 * @param _value uint256 the _value of tokens to be transferred
 * @return bool whether the transfer was successful or not
 */
function safeTransfer(IERC20 _token, address _to, uint256 _value) internal returns (bool) {
        uint256 prevBalance = _token.balanceOf(address(this));

        if (prevBalance < _value) {
            // Insufficient funds
            return false;
        }

        address(_token).call(
           abi.encodeWithSignature("transfer(address,uint256)", _to, _value)
        );

        // Fail if the new balance its not equal than previous balance sub _value
        return prevBalance - _value == _token.balanceOf(address(this));
    }
// Solidity 0.5.16
/**
 @notice Withdraw the accumulated amount of the fee
 
 @dev Only the owner of the contract can send this transaction
 
 @param _token The address of the token to withdraw
 @param _to The address destination of the tokens
 @param _amount The amount to withdraw
 */
function emytoWithdraw(
        IERC20 _token,
        address _to,
        uint256 _amount
    ) external onlyOwner {
        require(_to != address(0), "emytoWithdraw: The to address 0 its invalid");

        emytoBalances[address(_token)] = emytoBalances[address(_token)].sub(_amount);

        require(
            _token.safeTransfer(_to, _amount),
            "emytoWithdraw: Error transfer to emyto"
        );

        emit EmytoWithdraw(_token, _to, _amount);
    }
// Solidity 0.5.16
/**
 @notice Calculate the escrow id
 
 @dev The id of the escrow its generate with keccak256 function using the parameters of the function
 
 @param _agent The agent address
 @param _depositant The depositant address
 @param _retreader The retreader address
 @param _fee The fee percentage(calculate in BASE), this fee will sent to the agent when the escrow is withdrawn
 @param _token The token address
 @param _salt An entropy value, used to generate the id
 
 @return The id of the escrow
 */
function calculateId(
        address _agent,
        address _depositant,
        address _retreader,
        uint256 _fee,
        IERC20 _token,
        uint256 _salt
    ) public view returns(bytes32) {
        return keccak256(
            abi.encodePacked(
                address(this),
                _agent,
                _depositant,
                _retreader,
                _fee,
                _token,
                _salt
            )
        );
    }
// Solidity 0.5.16
/**
 @notice Create an escrow, using the signature provided by the agent
 
 @dev The signature can will be cancel with cancelSignature function
 
 @param _agent The agent address
 @param _depositant The depositant address
 @param _retreader The retrea    der address
 @param _fee The fee percentage(calculate in BASE), this fee will sent to the agent when the escrow is withdrawn
 @param _token The token address
 @param _salt An entropy value, used to generate the id
 @param _agentSignature The signature provided by the agent
 
 @return The id of the escrow
 */
function signedCreateEscrow(
        address _agent,
        address _depositant,
        address _retreader,
        uint256 _fee,
        IERC20 _token,
        uint256 _salt,
        bytes calldata _agentSignature
    ) external returns(bytes32 escrowId) {
        escrowId = _createEscrow(
            _agent,
            _depositant,
            _retreader,
            _fee,
            _token,
            _salt
        );

        require(!canceledSignatures[_agent][_agentSignature], "signedCreateEscrow: The signature was canceled");

        require(
            _agent == _ecrecovery(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", escrowId)), _agentSignature),
            "signedCreateEscrow: Invalid agent signature"
        );

        emit SignedCreateEscrow(escrowId, _agentSignature);
    }
// Solidity 0.5.16
/**
 @notice Deposit an amount valuate in escrow token to an escrow
 
 @dev The depositant of the escrow should be the sender, previous need the approve of the ERC20 tokens
 
 @param _escrowId The id of the escrow
 @param _amount The amount to deposit in an escrow, with emyto fee amount
 */
function deposit(bytes32 _escrowId, uint256 _amount) external {
        Escrow storage escrow = escrows[_escrowId];
        require(msg.sender == escrow.depositant, "deposit: The sender should be the depositant");

        uint256 toEmyto = _feeAmount(_amount, emytoFee);

        // Transfer the tokens
        require(
            escrow.token.safeTransferFrom(msg.sender, address(this), _amount),
            "deposit: Error deposit tokens"
        );

        // Assign the fee amount to emyto
        emytoBalances[address(escrow.token)] += toEmyto;
        // Assign the deposit amount to the escrow, subtracting the fee emyto amount
        uint256 toEscrow = _amount.sub(toEmyto);
        escrow.balance += toEscrow;

        emit Deposit(_escrowId, toEscrow, toEmyto);
    }
// Solidity 0.5.16
/**
 @notice Cancel an escrow and send the balance of the escrow to the depositant address
 
 @dev The sender should be the agent of the escrow
 The escrow will deleted
 
 @param _escrowId The id of the escrow
 */
function cancel(bytes32 _escrowId) external {
        Escrow storage escrow = escrows[_escrowId];
        require(msg.sender == escrow.agent, "cancel: The sender should be the agent");

        uint256 balance = escrow.balance;
        address depositant = escrow.depositant;
        IERC20 token = escrow.token;

        // Delete escrow
        delete escrows[_escrowId];

        // Send the tokens to the depositant if the escrow have balance
        if (balance != 0)
            require(
                token.safeTransfer(depositant, balance),
                "cancel: Error transfer to the depositant"
            );

        emit Cancel(_escrowId, balance);
    }
// Solidity 0.5.16
/**
 @notice Withdraw an amount from an escrow and send to _to address
 
 @dev The sender should be the _approved or the agent of the escrow
 
 @param _escrowId The id of the escrow
 @param _approved The address of approved
 @param _to The address of gone the tokens
 @param _amount The base amount
 */
function _withdraw(
        bytes32 _escrowId,
        address _approved,
        address _to,
        uint256 _amount
    ) internal {
        Escrow storage escrow = escrows[_escrowId];
        require(msg.sender == _approved || msg.sender == escrow.agent, "_withdraw: The sender should be the _approved or the agent");

        // Calculate the fee
        uint256 toAgent = _feeAmount(_amount, escrow.fee);
        // Actualize escrow balance in storage
        escrow.balance = escrow.balance.sub(_amount);
        // Send fee to the agent
        require(
            escrow.token.safeTransfer(escrow.agent, toAgent),
            "_withdraw: Error transfer tokens to the agent"
        );
        // Substract the agent fee
        uint256 toAmount = _amount.sub(toAgent);
        // Send amount to the _to
        require(
            escrow.token.safeTransfer(_to, toAmount),
            "_withdraw: Error transfer to the _to"
        );

        emit Withdraw(_escrowId, msg.sender, _to, toAmount, toAgent);
    }
// Solidity 0.8.11
/// @notice Claim one teji with whitelist proof.
/// @param signature Whitelist proof signature.
function claimWhitelist(bytes memory signature) external {
    require(_currentIndex < 1000, "Tejiverse: max supply exceeded");
    require(saleState == 1, "Tejiverse: whitelist sale is not open");
    require(!_boughtPresale[msg.sender], "Tejiverse: already claimed");

    bytes32 digest = keccak256(abi.encodePacked(address(this), msg.sender));
    require(digest.toEthSignedMessageHash().recover(signature) == signer, "Tejiverse: invalid signature");

    _boughtPresale[msg.sender] = true;
    _safeMint(msg.sender, 1);
  }
// Solidity 0.4.16
/**
 @dev claims the caller's tokens, converts them to any other token in the standard network
 by following a predefined conversion path and transfers the result tokens to a target account
 note that allowance must be set beforehand
 
 @param _path        conversion path, see conversion path format above
 @param _amount      amount to convert from (in the initial source token)
 @param _minReturn   if the conversion results in an amount smaller than the minimum return - it is cancelled, must be nonzero
 @param _for         account that will receive the conversion result
 
 @return tokens issued in return
 */
function claimAndConvertFor(IERC20Token[] _path, uint256 _amount, uint256 _minReturn, address _for) public returns (uint256) {
        // we need to transfer the tokens from the caller to the converter before we follow
        // the conversion path, to allow it to execute the conversion on behalf of the caller
        // note: we assume we already have allowance
        IERC20Token fromToken = _path[0];
        assert(fromToken.transferFrom(msg.sender, this, _amount));
        return convertFor(_path, _amount, _minReturn, _for);
    }
// Solidity 0.4.16
/**
 @dev utility, checks whether allowance for the given spender exists and approves one if it doesn't
 
 @param _token   token to check the allowance in
 @param _spender approved address
 @param _value   allowance amount
 */
function ensureAllowance(IERC20Token _token, address _spender, uint256 _value) private {
        // check if allowance for the given amount already exists
        if (_token.allowance(this, _spender) >= _value)
            return;

        // if the allowance is nonzero, must reset it to 0 first
        if (_token.allowance(this, _spender) != 0)
            assert(_token.approve(_spender, 0));

        // approve the new allowance
        assert(_token.approve(_spender, _value));
    }
// Solidity 0.4.24
/**
 	 * @notice Withdraw funds from the tokens contract
 	 */
function fundICO(uint256 _amount, uint8 _stage) public returns (bool) {
		if(nextStage !=_stage) {
			error('Escrow: ICO stage already funded');
			return false;
		}

		if (msg.sender != addressSCICO || tx.origin != owner) {
			error('Escrow: not allowed to fund the ICO');
			return false;
		}
		if (deposited[this]<_amount) {
			error('Escrow: not enough balance');
			return false;
		}
		bool success = SCTokens.transfer(addressSCICO, _amount);
		if(success) {
			deposited[this] = deposited[this].sub(_amount);
			nextStage++;
			emit FundICO(addressSCICO, _amount);
		}
		return success;
	}
// Solidity 0.4.24
/**
 	 * @notice Send _amount amount of tokens to address _to
 	 */
function transfer(address _to, uint256 _amount) public notTimeLocked stopInEmergency returns (bool success) {
		if (balances[msg.sender] < _amount) {
			error('transfer: the amount to transfer is higher than your token balance');
			return false;
		}

		if(!SCComplianceService.validate(msg.sender, _to, _amount)) {
			error('transfer: not allowed by the compliance service');
			return false;
		}

		balances[msg.sender] = balances[msg.sender].sub(_amount);
		balances[_to] = balances[_to].add(_amount);
		emit Transfer(msg.sender, _to, _amount); // Event log

		return true;
	}