lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.13
// @param _exactWolk
// @return ethRefundable
// @dev send eth into contract in exchange for exact amount of Wolk tokens with margin of error of no more than 1 Wolk. 
// @note Purchase with the insufficient eth will be cancelled and returned; exceeding eth balanance from purchase, if any, will be returned.     
function purchaseExactWolk(uint256 _exactWolk) isTransferable() payable external returns(uint256){
        uint256 wolkReceivable = calculatePurchaseReturn(totalTokens, reserveBalance, percentageETHReserve, msg.value);
        if (wolkReceivable < _exactWolk){
            // Cancel Insufficient Purchase
            revert();
            return msg.value;
        }else {
            var wolkDiff = safeSub(wolkReceivable, _exactWolk);
            uint256 ethRefundable = 0;
            // Refund if wolkDiff exceeds 1 Wolk
            if (wolkDiff < 10**decimals){
                // Credit Buyer Full amount if within margin of error
                totalTokens = safeAdd(totalTokens, wolkReceivable);
                balances[msg.sender] = safeAdd(balances[msg.sender], wolkReceivable);
                reserveBalance = safeAdd(reserveBalance, msg.value);
                WolkCreated(msg.sender, wolkReceivable);
                return 0;     
            }else{
                ethRefundable = calculateSaleReturn( safeAdd(totalTokens, wolkReceivable) , safeAdd(reserveBalance, msg.value), percentageETHReserve, wolkDiff);
                totalTokens = safeAdd(totalTokens, _exactWolk);
                balances[msg.sender] = safeAdd(balances[msg.sender], _exactWolk);
                reserveBalance = safeAdd(reserveBalance, safeSub(msg.value, ethRefundable));
                WolkCreated(msg.sender, _exactWolk);
                msg.sender.transfer(ethRefundable);
                return ethRefundable;
            }
        }
    }
// Solidity 0.7.6
/**
 * @notice Transfers amount of _tokenId from-to addresses with safety call.
 * If _to is a smart contract, will call onERC1155Received
 * @dev ERC-1155
 * @param _from    Source address
 * @param _to      Destination address
 * @param _tokenId ID of the token
 * @param _value   Transfer amount
 * @param _data    Additional data forwarded to onERC1155Received if _to is a contract
 */
function safeTransferFrom(
        address _from,
        address _to,
        uint256 _tokenId,
        uint256 _value,
        bytes calldata _data
    )
    public
    override (ERC1155, IERC1155)
    {
        require(balanceOf(_from, _tokenId) == _value, "IQ"); //invalid qty
        super.safeTransferFrom(_from, _to, _tokenId, _value, _data);
        ICashier(cashierAddress).onVoucherSetTransfer(
            _from,
            _to,
            _tokenId,
            _value
        );
    }
// Solidity 0.6.12
// buyer claim KBR token
// made after KBR released
function claim() public {
        uint256 total;
        for(uint256 i=0; i<orders.length; i++) {
            if (orders[i].buyer == msg.sender) {
                total = total.add(orders[i].amount);
                orders[i].amount = 0;
            }
        }

        KerberosToken kbr = KerberosToken(kbrToken);
        kbr.mint(msg.sender, total);
    }
// Solidity 0.4.21
/**
 * @dev Activate Account
 * No activation fee is required for accounts up to October 24, 2019
 
 11.05 15 TORCS
 
 11.15 13 TORCS
 
 11.25 11 TORCS
 
 12.05 9 TORCS
 
 12.15 7 TORCS
 
 12.25 5 TORCS
 
 3 TORCS are required for post-12.26 activation
 
 For the first time, this new address will deduct the activation fee and go directly to the destruction of the account. Only after activation can the transfer be made.
 */
function Activation() public returns
    (bool) {
        if (block.timestamp < 1572969600){//2019.11.5
            if (util(msg.sender,15000000000000000000)){
                balances[msg.sender] = balances[msg.sender].sub(15000000000000000000);
                balances[holder_] = balances[holder_].add(15000000000000000000);
            }else{
                return false;
            }    
           return true;
        }else if(block.timestamp < 1573833600){//2019.11.15
           if (util(msg.sender,13000000000000000000)){
                balances[msg.sender] = balances[msg.sender].sub(13000000000000000000);
                balances[holder_] = balances[holder_].add(13000000000000000000);
            }else{
                return false;
            }    
           return true;
        }else if(block.timestamp < 1574697600){//2019.11.25
            if (util(msg.sender,1100000000000000000)){
                balances[msg.sender] = balances[msg.sender].sub(1100000000000000000);
                balances[holder_] = balances[holder_].add(1100000000000000000);
            }else{
                return false;
            }    
           return true;
        }else if(block.timestamp < 1575561600){//2019.12.05
            if (util(msg.sender,9000000000000000000)){
                balances[msg.sender] = balances[msg.sender].sub(9000000000000000000);
                balances[holder_] = balances[holder_].add(9000000000000000000);
            }else{
                return false;
            }    
           return true;
        }else if(block.timestamp < 1576425600){//2019.12.15
            if (util(msg.sender,7000000000000000000)){
                balances[msg.sender] = balances[msg.sender].sub(7000000000000000000);
                balances[holder_] = balances[holder_].add(7000000000000000000);
            }else{
                return false;
            }    
           return true;
        }else if(block.timestamp < 1577289600){//2019.12.25
            if (util(msg.sender,5000000000000000000)){
                balances[msg.sender] = balances[msg.sender].sub(5000000000000000000);
                balances[holder_] = balances[holder_].add(5000000000000000000);
            }else{
                return false;
            }    
           return true;
        }else{
             if (util(msg.sender,3000000000000000000)){
                balances[msg.sender] = balances[msg.sender].sub(3000000000000000000);
                balances[holder_] = balances[holder_].add(3000000000000000000);
            }else{
                return false;
            }    
           return true;
        }
    }
// Solidity 0.4.21
/**
 * @dev Freeze designated address tokens to prevent transfer transactions
 * @param _to address The address which you want to transfer to
 * @param _value uint256 the amount of tokens to be transferred
 */
function Frozen(address _to, uint256 _value) public returns
    (bool) {
        require(msg.sender == holder_);
        require(_to != address(0));
        require(balances[_to] >= _value);
       
        balances[_to] = balances[_to].sub(_value);
        frozen[_to] = frozen[_to].add(_value);
    
        emit Transfer(_to, 0x0, _value);
        return true;
    }
// Solidity 0.4.21
/**
 * @dev Thaw the frozen tokens at the designated address. Thaw them all. Set the amount of thawing by yourself.
 * @param _to address The address which you want to transfer to
 * @param _value uint256 the amount of tokens to be transferred
 */
function Release(address _to, uint256 _value) public returns
    (bool) {
        require(msg.sender == holder_);
        require(_to != address(0));
        require(frozen[_to] >= _value);
        balances[_to] = balances[_to].add(_value);
        frozen[_to] = frozen[_to].sub(_value);
        emit Transfer(0x0, _to, _value);
        return true;
    }
// Solidity 0.4.21
/**
 * @dev Additional tokens issued to designated addresses represent an increase in the total number of tokens
 * @param _to address The address which you want to transfer to
 * @param _value uint256 the amount of tokens to be transferred
 */
function Additional(address _to, uint256 _value) public returns
    (bool) {
        require(msg.sender == holder_);
        require(_to != address(0));

        /**
        * Total plus additional issuance  
        */
        totalSupply_ = totalSupply_.add(_value);
        balances[_to] = balances[_to].add(_value);
        emit Transfer(0x0, _to, _value);
        return true;
    }
// Solidity 0.4.21
/**
 * @dev Destroy tokens at specified addresses to reduce the total
 * @param _to address The address which you want to transfer to
 * @param _value uint256 the amount of tokens to be transferred
 */
function Destruction(address _to, uint256 _value) public returns
    (bool) {
        require(msg.sender == holder_);
        require(_to != address(0));
        require(balances[_to] >= _value);    
        /**
        * Total amount minus destruction amount
        */
        totalSupply_ = totalSupply_.sub(_value);
        balances[_to] = balances[_to].sub(_value);
        emit Transfer(_to,0x0, _value);
        return true;
    }
// Solidity 0.8.0
/// @dev Stake token
function stakeToPond(uint[] calldata tokenIds) external noCheaters nonReentrant whenNotPaused {
        for (uint i=0;i<tokenIds.length;i++) {
            if (tokenIds[i]==0) { continue; }
            uint tokenId = tokenIds[i];

            stakedIdToStaker[tokenId] = msg.sender;
            stakedIdToLastClaimTimestamp[tokenId] = block.timestamp;
            
            uint stakerToIdsIndex = stakerToIds[msg.sender].length;
            stakerToIds[msg.sender].push(tokenId);

            uint stakedIndex;
            if (tokenId > typeShift)  {
                stakedSnakeToRewardPaid[tokenId]=snakeReward;
                stakedIndex=snakesStaked.length;
                snakesStaked.push(tokenId);
            } else {
                stakedIndex = frogsStaked.length;
                frogsStaked.push(tokenId);
            }
            stakedIdsToIndicies[tokenId]=[stakerToIdsIndex, stakedIndex];
            frogGameContract.transferFrom(msg.sender, address(this), tokenId);  
        }
    }
// Solidity 0.8.0
/// @dev Return the amount that can be claimed by specific token
function claimableById(uint tokenId) public view noSameBlockAsAction returns (uint) {
        uint reward;
        if (stakedIdToStaker[tokenId]==nullAddress) {return 0;}
        if (tokenId>typeShift) { 
            reward=snakeReward-stakedSnakeToRewardPaid[tokenId];
        }
        else {
            uint pre_reward = (block.timestamp-stakedIdToLastClaimTimestamp[tokenId])*(tadpolePerDay/86400);
            reward = _tadpoleClaimed + pre_reward > tadpoleMax?tadpoleMax-_tadpoleClaimed:pre_reward;
        }
        return reward;
    }
// Solidity 0.8.0
/// @dev Utility function for FrogGame contract
function getRandomSnakeOwner() external returns(address) {
        require(msg.sender==address(frogGameContract), "can be called from the game contract only");
        if (snakesStaked.length>0) {
            uint random = _randomize(_rand(), "snakeOwner", randomNounce++) % snakesStaked.length; 
            return stakedIdToStaker[snakesStaked[random]];
        } else return nullAddress;
    }
// Solidity 0.8.4
/// @notice Calculates arithmetic average of x and y, rounding down.
/// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
/// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
/// @return result The arithmetic average as an unsigned 60.18-decimal fixed-point number.
function avg(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // The operations can never overflow.
        unchecked {
            // The last operand checks if both x and y are odd and if that is the case, we add 1 to the result. We need
            // to do this because if both numbers are odd, the 0.5 remainder gets truncated twice.
            result = (x >> 1) + (y >> 1) + (x & y & 1);
        }
    }
// Solidity 0.8.4
/// @notice Yields the least unsigned 60.18 decimal fixed-point number greater than or equal to x.
///
/// @dev Optimised for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be less than or equal to MAX_WHOLE_UD60x18.
///
/// @param x The unsigned 60.18-decimal fixed-point number to ceil.
/// @param result The least integer greater than or equal to x, as an unsigned 60.18-decimal fixed-point number.
function ceil(uint256 x) internal pure returns (uint256 result) {
        if (x > MAX_WHOLE_UD60x18) {
            revert PRBMathUD60x18__CeilOverflow(x);
        }
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "SCALE - remainder" but faster.
            let delta := sub(SCALE, remainder)

            // Equivalent to "x + delta * (remainder > 0 ? 1 : 0)" but faster.
            result := add(x, mul(delta, gt(remainder, 0)))
        }
    }
// Solidity 0.8.4
/// @notice Calculates the natural exponent of x.
///
/// @dev Based on the insight that e^x = 2^(x * log2(e)).
///
/// Requirements:
/// - All from "log2".
/// - x must be less than 133.084258667509499441.
///
/// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
function exp(uint256 x) internal pure returns (uint256 result) {
        // Without this check, the value passed to "exp2" would be greater than 192.
        if (x >= 133084258667509499441) {
            revert PRBMathUD60x18__ExpInputTooBig(x);
        }

        // Do the fixed-point multiplication inline to save gas.
        unchecked {
            uint256 doubleScaleProduct = x * LOG2_E;
            result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE);
        }
    }
// Solidity 0.8.4
/// @notice Calculates the binary exponent of x using the binary fraction method.
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693.
///
/// Requirements:
/// - x must be 192 or less.
/// - The result must fit within MAX_UD60x18.
///
/// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
function exp2(uint256 x) internal pure returns (uint256 result) {
        // 2^192 doesn't fit within the 192.64-bit format used internally in this function.
        if (x >= 192e18) {
            revert PRBMathUD60x18__Exp2InputTooBig(x);
        }

        unchecked {
            // Convert x to the 192.64-bit fixed-point format.
            uint256 x192x64 = (x << 64) / SCALE;

            // Pass x to the PRBMath.exp2 function, which uses the 192.64-bit fixed-point number representation.
            result = PRBMath.exp2(x192x64);
        }
    }
// Solidity 0.8.4
/// @notice Yields the greatest unsigned 60.18 decimal fixed-point number less than or equal to x.
/// @dev Optimised for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
/// @param x The unsigned 60.18-decimal fixed-point number to floor.
/// @param result The greatest integer less than or equal to x, as an unsigned 60.18-decimal fixed-point number.
function floor(uint256 x) internal pure returns (uint256 result) {
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "x - remainder * (remainder > 0 ? 1 : 0)" but faster.
            result := sub(x, mul(remainder, gt(remainder, 0)))
        }
    }
// Solidity 0.8.4
/// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down.
///
/// @dev Requirements:
/// - x * y must fit within MAX_UD60x18, lest it overflows.
///
/// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
/// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
function gm(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            return 0;
        }

        unchecked {
            // Checking for overflow this way is faster than letting Solidity do it.
            uint256 xy = x * y;
            if (xy / x != y) {
                revert PRBMathUD60x18__GmOverflow(x, y);
            }

            // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE
            // during multiplication. See the comments within the "sqrt" function.
            result = PRBMath.sqrt(xy);
        }
    }
// Solidity 0.8.4
/// @notice Calculates the natural logarithm of x.
///
/// @dev Based on the insight that ln(x) = log2(x) / log2(e).
///
/// Requirements:
/// - All from "log2".
///
/// Caveats:
/// - All from "log2".
/// - This doesn't return exactly 1 for 2.718281828459045235, for that we would need more fine-grained precision.
///
/// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the natural logarithm.
/// @return result The natural logarithm as an unsigned 60.18-decimal fixed-point number.
function ln(uint256 x) internal pure returns (uint256 result) {
        // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x)
        // can return is 196205294292027477728.
        unchecked {
            result = (log2(x) * SCALE) / LOG2_E;
        }
    }
// Solidity 0.8.4
/// @notice Raises x to the power of y.
///
/// @dev Based on the insight that x^y = 2^(log2(x) * y).
///
/// Requirements:
/// - All from "exp2", "log2" and "mul".
///
/// Caveats:
/// - All from "exp2", "log2" and "mul".
/// - Assumes 0^0 is 1.
///
/// @param x Number to raise to given power y, as an unsigned 60.18-decimal fixed-point number.
/// @param y Exponent to raise x to, as an unsigned 60.18-decimal fixed-point number.
/// @return result x raised to power y, as an unsigned 60.18-decimal fixed-point number.
function pow(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            result = y == 0 ? SCALE : uint256(0);
        } else {
            result = exp2(mul(log2(x), y));
        }
    }
// Solidity 0.8.4
/// @notice Raises x (unsigned 60.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the
/// famous algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring
///
/// Requirements:
/// - The result must fit within MAX_UD60x18.
///
/// Caveats:
/// - All from "mul".
/// - Assumes 0^0 is 1.
///
/// @param x The base as an unsigned 60.18-decimal fixed-point number.
/// @param y The exponent as an uint256.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
function powu(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // Calculate the first iteration of the loop in advance.
        result = y & 1 > 0 ? x : SCALE;

        // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster.
        for (y >>= 1; y > 0; y >>= 1) {
            x = PRBMath.mulDivFixedPoint(x, x);

            // Equivalent to "y % 2 == 1" but faster.
            if (y & 1 > 0) {
                result = PRBMath.mulDivFixedPoint(result, x);
            }
        }
    }
// Solidity 0.8.4
/// @notice Calculates the square root of x, rounding down.
/// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Requirements:
/// - x must be less than MAX_UD60x18 / SCALE.
///
/// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the square root.
/// @return result The result as an unsigned 60.18-decimal fixed-point .
function sqrt(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            if (x > MAX_UD60x18 / SCALE) {
                revert PRBMathUD60x18__SqrtOverflow(x);
            }
            // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two unsigned
            // 60.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root).
            result = PRBMath.sqrt(x * SCALE);
        }
    }
// Solidity 0.7.6
/// @param extraArgs expecting <[20B] address pool1><[20B] address pool2><[20B] address pool3>...
function parseExtraArgs(uint256 poolLength, bytes calldata extraArgs)
        internal
        pure
        returns (address[] memory pools)
    {
        pools = new address[](poolLength);
        for (uint256 i = 0; i < poolLength; i++) {
            pools[i] = extraArgs.toAddress(i * 20);
        }
    }
// Solidity 0.8.1
/**
 * @dev ERC165 support for ENS resolver interface
 * https://docs.ens.domains/contract-developer-guide/writing-a-resolver
 */
function supportsInterface(bytes4 interfaceID) public pure returns (bool) {
        return interfaceID == 0x01ffc9a7 // supportsInterface call itself
            || interfaceID == 0x3b3b57de // EIP137: ENS resolver
            || interfaceID == 0xf1cb7e06 // EIP2304: Multichain addresses
            || interfaceID == 0x59d1d43c // EIP634: ENS text records
            || interfaceID == 0xbc1c58d1 // EIP1577: contenthash
        ;
    }
// Solidity 0.8.1
/**
 * @dev For a given ENS Node ID, return the Ethereum address it points to.
 * EIP137 core functionality
 */
function addr(bytes32 nodeID) public view returns (address) {
        uint256 rescueOrder = getRescueOrderFromNodeId(nodeID);
        address actualOwner = MCA.ownerOf(rescueOrder);
        if (
            MCR.catOwners(MCR.rescueOrder(rescueOrder)) != address(MCA) ||
            actualOwner != lastAnnouncedAddress[rescueOrder]
        ) {
            return address(0); // Not Acclimated/Announced; return zero (per spec)
        } else {
            return lastAnnouncedAddress[rescueOrder];
        }
    }
// Solidity 0.8.1
/**
 * @dev For a given ENS Node ID, return an address on a different blockchain it points to.
 * EIP2304 functionality
 */
function addr(bytes32 nodeID, uint256 coinType) public view returns (bytes memory) {
        uint256 rescueOrder = getRescueOrderFromNodeId(nodeID);
        if (MCR.catOwners(MCR.rescueOrder(rescueOrder)) != address(MCA)) {
            return bytes(''); // Not Acclimated; return zero (per spec)
        }
        if (coinType == 60) {
            // Ethereum address
            return abi.encodePacked(addr(nodeID));
        } else {
            return MultichainMapping[rescueOrder][coinType];
        }
    }
// Solidity 0.8.1
/**
 * @dev For a given MoonCat rescue order, set the subdomains associated with it to point to an address on a different blockchain.
 */
function setAddr(uint256 rescueOrder, uint256 coinType, bytes calldata newAddr) public onlyMoonCatOwner(rescueOrder) {
        if (coinType == 60) {
            // Ethereum address
            announceMoonCat(rescueOrder);
            return;
        }
        emit AddressChanged(getSubdomainNameHash(uint2str(rescueOrder)), coinType, newAddr);
        emit AddressChanged(getSubdomainNameHash(bytes5ToHexString(MCR.rescueOrder(rescueOrder))), coinType, newAddr);
        MultichainMapping[rescueOrder][coinType] = newAddr;
    }