lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @notice Remove liquidity from the pool all in one token.
 * @param self Swap struct to read from and write to
 * @param tokenAmount the amount of the lp tokens to burn
 * @param tokenIndex the index of the token you want to receive
 * @param minAmount the minimum amount to withdraw, otherwise revert
 * @return amount chosen token that user received
 */
function removeLiquidityOneToken(
        Swap storage self,
        uint256 tokenAmount,
        uint8 tokenIndex,
        uint256 minAmount
    ) external returns (uint256) {
        LPToken lpToken = self.lpToken;
        IERC20[] memory pooledTokens = self.pooledTokens;

        require(tokenAmount <= lpToken.balanceOf(msg.sender), ">LP.balanceOf");
        require(tokenIndex < pooledTokens.length, "Token not found");

        uint256 totalSupply = lpToken.totalSupply();

        (uint256 dy, uint256 dyFee) = _calculateWithdrawOneToken(
            self,
            msg.sender,
            tokenAmount,
            tokenIndex,
            totalSupply
        );

        require(dy >= minAmount, "dy < minAmount");

        self.balances[tokenIndex] = self.balances[tokenIndex].sub(
            dy.add(dyFee.mul(self.adminFee).div(FEE_DENOMINATOR))
        );
        lpToken.burnFrom(msg.sender, tokenAmount);
        pooledTokens[tokenIndex].safeTransfer(msg.sender, dy);

        emit RemoveLiquidityOne(
            msg.sender,
            tokenAmount,
            totalSupply,
            tokenIndex,
            dy
        );

        return dy;
    }
// Solidity 0.6.12
/**
 * @notice withdraw all admin fees to a given address
 * @param self Swap struct to withdraw fees from
 * @param to Address to send the fees to
 */
function withdrawAdminFees(Swap storage self, address to) external {
        IERC20[] memory pooledTokens = self.pooledTokens;
        for (uint256 i = 0; i < pooledTokens.length; i++) {
            IERC20 token = pooledTokens[i];
            uint256 balance = token.balanceOf(address(this)).sub(
                self.balances[i]
            );
            if (balance != 0) {
                token.safeTransfer(to, balance);
            }
        }
    }
// Solidity 0.7.6
/**
 * @dev Change the name of the asteroid
 */
function setName(uint _asteroidId, string memory _newName) external whenNotPaused {
    require(_msgSender() == token.ownerOf(_asteroidId), "ERC721: caller is not the owner");
    require(validateName(_newName) == true, "Invalid name");
    require(isNameUsed(_newName) == false, "Name already in use");

    // If already named, dereserve old name
    if (bytes(_asteroidNames[_asteroidId]).length > 0) {
      toggleNameUsed(_asteroidNames[_asteroidId], false);
    }

    toggleNameUsed(_newName, true);
    _asteroidNames[_asteroidId] = _newName;
    emit NameChanged(_asteroidId, _newName);
  }
// Solidity 0.7.6
/**
 * @dev Check if the name string is valid
 * Between 1 and 32 characters (Alphanumeric and spaces without leading or trailing space)
 */
function validateName(string memory str) public pure returns (bool){
    bytes memory b = bytes(str);

    if(b.length < 1) return false;
    if(b.length > 32) return false; // Cannot be longer than 25 characters
    if(b[0] == 0x20) return false; // Leading space
    if (b[b.length - 1] == 0x20) return false; // Trailing space

    bytes1 lastChar = b[0];

    for (uint i; i < b.length; i++) {
      bytes1 char = b[i];

      if (char == 0x20 && lastChar == 0x20) return false; // Cannot contain continous spaces

      if (
        !(char >= 0x30 && char <= 0x39) && //9-0
        !(char >= 0x41 && char <= 0x5A) && //A-Z
        !(char >= 0x61 && char <= 0x7A) && //a-z
        !(char == 0x20) //space
      ) {
        return false;
      }

      lastChar = char;
    }

    return true;
  }
// Solidity 0.8.10
//@dev Prior approval by the "addressHoldingNFTs" of this deployed contract
// to the Timeless contract is required for all IDs that should be allowed to be exchanged
function exchangeTimeless(uint256 tokenId) external payable {
        require(tokenIdToAddress[tokenId] == msg.sender, "You are not allowed to buy one!");
        require(claimed[tokenId] == false, "TokenID already claimed!");
        require(msg.value == 0.222 ether, "Please send exactly 0.222 ETH");

        IERC721(timelessAddr).safeTransferFrom(addressHoldingNFTs, msg.sender, tokenId);

        claimed[tokenId] = true;
        leftUnclaimed--;
    }
// Solidity 0.8.0
/**
 * @notice create and deploy multiple vest contracts.
 * @notice can be called by onlyOwner.
 * @param startTime vesting startTime in EPOCH.
 * @param endTime vesting endTime in EPOCH.
 * @param cliff duration when claim starts.
 * @param unlockDuration every liner unlocking schedule in seconds.
 * @param allowReleaseAll allow release All once.
 * @return vestAddress A vesting address.
 */
function createVest(
        uint256 startTime,
        uint256 endTime,
        uint256 cliff,
        uint256 unlockDuration,
        bool allowReleaseAll
    ) external onlyOwner returns (address vestAddress) {
        vestAddress = address(
            new UnifarmVesting(
                _msgSender(),
                startTime.add(cliff),
                startTime,
                startTime.add(endTime),
                unlockDuration,
                allowReleaseAll,
                address(this)
            )
        );

        vested.push(vestAddress);
        emit Vested(vestAddress, block.timestamp);
    }
// Solidity 0.4.24
/**
 * Get base asset info
 */
function getAssetBaseInfo() public view onlyValid
        returns (
            uint _id,
            uint _assetPrice,
            bool _isTradable,
            string _remark1,
            string _remark2
        )
    {
        _id = id;
        _assetPrice = assetPrice;
        _isTradable = isTradable;

        _remark1 = remark1;
        _remark2 = remark2;
    }
// Solidity 0.4.24
/**
 * overwrite the transferOwnership interface in ownable.
 * Only can transfer when the token is not splitted into small keys.
 * After transfer, the token should be set in "no trading" status.
 */
function transferOwnership(address newowner) public onlyOwner onlyValid onlyUnsplitted {
        owner = newowner;
        isTradable = false;  // set to false for new owner

        emit TokenUpdateEvent (
            id,
            isValid,
            isTradable,
            owner,
            assetPrice,
            assetFile.link,
            legalFile.link
        );
    }
// Solidity 0.4.24
/**
 * Buy asset
 */
function buy() public payable onlyValid onlyUnsplitted {
        require(isTradable == true, "contract is tradeable");
        require(msg.value >= assetPrice, "assetPrice not match");
        address origin_owner = owner;

        owner = msg.sender;
        isTradable = false;  // set to false for new owner

        emit TokenUpdateEvent (
            id,
            isValid,
            isTradable,
            owner,
            assetPrice,
            assetFile.link,
            legalFile.link
        );

        uint priviousBalance = pendingWithdrawals[origin_owner];
        pendingWithdrawals[origin_owner] = priviousBalance.add(assetPrice);
    }
// Solidity 0.4.24
/**
 * 
 * Warning: may fail when number of owners exceeds 100 due to gas limit of a block in Ethereum.
 */
function distributeDivident(uint amount) public {
        // stableToken.approve(address(this), amount)
        // should be called by the caller to the token contract in previous
        uint value = 0;
        uint length = allowners.length;
        require(stableToken.balanceOf(msg.sender) >= amount, "Insufficient balance for sender");
        require(stableToken.allowance(msg.sender, address(this)) >= amount, "Insufficient allowance for contract");
        for (uint i = 0; i < length; i++) {
            //value = amount * balances[allowners[i]] / _totalSupply;
            value = amount.mul(balances[allowners[i]]);
            value = value.div(_totalSupply);

            // Always use a require when doing token transfer!
            // Do not think it works like the transfer method for ether,
            // which handles failure and will throw for you.
            require(stableToken.transferFrom(msg.sender, allowners[i], value));
        }
    }
// Solidity 0.4.24
/**
 * key inssurance. Split the whole token into small keys.
 * Only the owner can perform this when the token is still valid and unsplitted.
 * @param _supply Totol supply in ERC20 standard
 * @param _decim  Decimal parameter in ERC20 standard
 * @param _price The force acquisition price. If a claimer is willing to pay more than this value, he can
 * buy the keys forcibly. Notice: the claimer can only buy all keys at one time or buy nothing and the
 * buying process is delegated into a trusted agent. i.e. the operator.
 * @param _address The initial distribution plan for the keys. This parameter contains the addresses.
 * @param _amount  The amount corresponding to the initial distribution addresses.
 */
function split(uint _supply, uint8 _decim, uint _price, address[] _address, uint[] _amount)
        public
        onlyOwner
        onlyValid
        onlyUnsplitted
    {
        require(_address.length == _amount.length);

        isSplitted = true;
        _totalSupply = _supply * 10 ** uint(_decim);
        decimals = _decim;
        collectPrice = _price;

        uint amount = 0;
        uint length = _address.length;

        balances[msg.sender] = _totalSupply;
        if (indexOfowner[msg.sender] == 0) {
            allowners.push(msg.sender);
            indexOfowner[msg.sender] = allowners.length;
        }
        emit Transfer(address(0), msg.sender, _totalSupply);

        for (uint i = 0; i < length; i++) {
            amount = _amount[i]; // * 10 ** uint(_decim);
            balances[_address[i]] = amount;
            balances[msg.sender] = balances[msg.sender].sub(amount);

            // ensure that each address appears only once in allowners list
            // so that distribute divident or force collect only pays one time
            if (indexOfowner[_address[i]] == 0) {
                allowners.push(_address[i]);
                indexOfowner[_address[i]] = allowners.length;
            }
            emit Transfer(msg.sender, _address[i], amount);
        }

        emit TokenSplitEvent(id, _supply, _decim, _price);
    }
// Solidity 0.4.24
/**
 * Token conversion. Turn the keys to a whole token.
 * Only the sender with all keys in hand can perform this and he will be the new owner.
 */
function merge() public onlyValid onlySplitted {
        require(balances[msg.sender] == _totalSupply);
        _totalSupply = 0;
        balances[msg.sender] = 0;
        owner = msg.sender;
        isTradable = false;
        isSplitted = false;
        emit Transfer(msg.sender, address(0), _totalSupply);
        emit TokenMergeEvent(id, msg.sender);
    }
// Solidity 0.6.12
/**
 * @notice Calculates and returns A based on the ramp settings
 * @dev See the StableSwap paper for details
 * @param self Swap struct to read from
 * @return A parameter in its raw precision form
 */
function _getAPrecise(Swap storage self) internal view returns (uint256) {
        uint256 t1 = self.futureATime; // time when ramp is finished
        uint256 a1 = self.futureA; // final A value when ramp is finished

        if (block.timestamp < t1) {
            uint256 t0 = self.initialATime; // time when ramp is started
            uint256 a0 = self.initialA; // initial A value when ramp is started
            if (a1 > a0) {
                // a0 + (a1 - a0) * (block.timestamp - t0) / (t1 - t0)
                return
                    a0.add(
                        a1.sub(a0).mul(block.timestamp.sub(t0)).div(t1.sub(t0))
                    );
            } else {
                // a0 - (a0 - a1) * (block.timestamp - t0) / (t1 - t0)
                return
                    a0.sub(
                        a0.sub(a1).mul(block.timestamp.sub(t0)).div(t1.sub(t0))
                    );
            }
        } else {
            return a1;
        }
    }
// Solidity 0.6.6
/**
 * @notice Get the ETHUSD price from ChainLink and convert to a mantissa value
 * @return USD price mantissa
 */
function getETHUSDCPrice() public view returns (uint256) {
        (
            uint80 roundID,
            int256 price,
            uint256 startedAt,
            uint256 timeStamp,
            uint80 answeredInRound
        ) = priceFeedETHUSD.latestRoundData();
        // Get decimals of price feed
        uint256 decimals = priceFeedETHUSD.decimals();
        // Add decimal places to format an 18 decimal mantissa
        uint256 priceMantissa =
            uint256(price).mul(10**(mantissaDecimals.sub(decimals)));

        return priceMantissa;
    }
// Solidity 0.6.12
/**
 * @notice Calculate the fee that is applied when the given user withdraws.
 * Withdraw fee decays linearly over 4 weeks.
 * @param user address you want to calculate withdraw fee of
 * @return current withdraw fee of the user
 */
function calculateCurrentWithdrawFee(Swap storage self, address user)
        public
        view
        returns (uint256)
    {
        uint256 endTime = self.depositTimestamp[user].add(4 weeks);
        if (endTime > block.timestamp) {
            uint256 timeLeftover = endTime.sub(block.timestamp);
            return
                self
                    .defaultWithdrawFee
                    .mul(self.withdrawFeeMultiplier[user])
                    .mul(timeLeftover)
                    .div(4 weeks)
                    .div(FEE_DENOMINATOR);
        }
        return 0;
    }
// Solidity 0.8.0
// mints new DSProxies and stores them to the proxy array
function mint(uint256 _value) public {
        require(_value % 1e18 == 0);

        uint newTokens = _value / 1e18;

        for (uint256 i = 0; i < newTokens; i++) {
            address proxy = address(makeChild());
            _proxies.push(proxy);
        }
        _mint(_msgSender(), _value);
    }
// Solidity 0.6.12
/*
 * createLGEWhitelist - Call this after initial Token Generation Event (TGE) 
 * 
 * pairAddress - address generated from createPair() event on DEX
 * durations - array of durations (seconds) for each whitelist rounds
 * amountsMax - array of max amounts (TOKEN decimals) for each whitelist round
 * 
 */
function createLGEWhitelist(address pairAddress, uint256[] calldata durations, uint256[] calldata amountsMax) external onlyWhitelister() {
        require(durations.length == amountsMax.length, "Invalid whitelist(s)");
        
        _lgePairAddress = pairAddress;
        
        if(durations.length > 0) {
            
            delete _lgeWhitelistRounds;
        
            for (uint256 i = 0; i < durations.length; i++) {
                _lgeWhitelistRounds.push(WhitelistRound(durations[i], amountsMax[i]));
            }
        
        }
    }
// Solidity 0.6.12
/*
 * modifyLGEWhitelistAddresses - Define what addresses are included/excluded from a whitelist round
 * 
 * index - 0-based index of round to modify whitelist
 * duration - period in seconds from LGE event or previous whitelist round
 * amountMax - max amount (TOKEN decimals) for each whitelist round
 * 
 */
function modifyLGEWhitelist(uint256 index, uint256 duration, uint256 amountMax, address[] calldata addresses, bool enabled) external onlyWhitelister() {
        require(index < _lgeWhitelistRounds.length, "Invalid index");
        require(amountMax > 0, "Invalid amountMax");

        if(duration != _lgeWhitelistRounds[index].duration)
            _lgeWhitelistRounds[index].duration = duration;
        
        if(amountMax != _lgeWhitelistRounds[index].amountMax)  
            _lgeWhitelistRounds[index].amountMax = amountMax;
        
        for (uint256 i = 0; i < addresses.length; i++) {
            _lgeWhitelistRounds[index].addresses[addresses[i]] = enabled;
        }
    }
// Solidity 0.6.12
/*
 *  getLGEWhitelistRound
 *
 *  returns:
 *
 *  1. whitelist round number ( 0 = no active round now )
 *  2. duration, in seconds, current whitelist round is active for
 *  3. timestamp current whitelist round closes at
 *  4. maximum amount a whitelister can purchase in this round
 *  5. is caller whitelisted
 *  6. how much caller has purchased in current whitelist round
 *
 */
function getLGEWhitelistRound() public view returns (uint256, uint256, uint256, uint256, bool, uint256) {
        
        if(_lgeTimestamp > 0) {
            
            uint256 wlCloseTimestampLast = _lgeTimestamp;
        
            for (uint256 i = 0; i < _lgeWhitelistRounds.length; i++) {
                
                WhitelistRound storage wlRound = _lgeWhitelistRounds[i];
                
                wlCloseTimestampLast = wlCloseTimestampLast.add(wlRound.duration);
                if(now <= wlCloseTimestampLast)
                    return (i.add(1), wlRound.duration, wlCloseTimestampLast, wlRound.amountMax, wlRound.addresses[_msgSender()], wlRound.purchased[_msgSender()]);
            }
        
        }
        
        return (0, 0, 0, 0, false, 0);
    }
// Solidity 0.6.12
/*
 * _applyLGEWhitelist - internal function to be called initially before any transfers
 * 
 */
function _applyLGEWhitelist(address sender, address recipient, uint256 amount) internal {
        
        if(_lgePairAddress == address(0) || _lgeWhitelistRounds.length == 0)
            return;
        
        if(_lgeTimestamp == 0 && sender != _lgePairAddress && recipient == _lgePairAddress && amount > 0)
            _lgeTimestamp = now;
        
        if(sender == _lgePairAddress && recipient != _lgePairAddress) {
            //buying
            
            (uint256 wlRoundNumber,,,,,) = getLGEWhitelistRound();
        
            if(wlRoundNumber > 0) {
                
                WhitelistRound storage wlRound = _lgeWhitelistRounds[wlRoundNumber.sub(1)];
                
                require(wlRound.addresses[recipient], "LGE - Buyer is not whitelisted");
                
                uint256 amountRemaining = 0;
                
                if(wlRound.purchased[recipient] < wlRound.amountMax)
                    amountRemaining = wlRound.amountMax.sub(wlRound.purchased[recipient]);
    
                require(amount <= amountRemaining, "LGE - Amount exceeds whitelist maximum");
                wlRound.purchased[recipient] = wlRound.purchased[recipient].add(amount);
                
            }
            
        }
        
    }
// Solidity 0.4.19
/// @dev purchase DGX gold
/// @param _block_number Block number from DTPO (Digix Trusted Price Oracle)
/// @param _nonce Nonce from DTPO
/// @param _wei_per_dgx_mg Price in wei for one milligram of DGX
/// @param _signer Address of the DTPO signer
/// @param _signature Signature of the payload
/// @return {
///   "_success": "returns true if operation is successful",
///   "_purchased_amount": "DGX nanograms received"
/// }
function purchase(uint256 _block_number, uint256 _nonce, uint256 _wei_per_dgx_mg, address _signer, bytes _signature)
           payable
           public
           returns (bool _success, uint256 _purchased_amount)
  {
    address _sender = msg.sender;

    (_success, _purchased_amount) =
      marketplace_controller().put_purchase_for.value(msg.value).gas(600000)(msg.value, _sender, _sender, _block_number,
                                                                             _nonce, _wei_per_dgx_mg, _signer, _signature);
    require(_success);
  }
// Solidity 0.4.18
/**
 * Function returning the current price of ToG
 * @dev can be used prior to the donation as a constant function but it is mainly used in the noname function
 * @param message should contain an encrypted contract info of the redeemer to setup a meeting
 */
function redeem(string message) {

        // Check caller has a token
        require (balances[msg.sender] >= 1);

        // Check tokens did not expire
        require (now <= expirationDate);

        // Lock the token against further transfers
        balances[msg.sender] -= 1;
        redeemed[msg.sender] += 1;

        // Call out
        tokenRedemption(msg.sender, message);
    }
// Solidity 0.6.12
/**
 * @return Current rebasing index of stETH in RAY
 **/
function _stEthRebasingIndex() internal view returns (uint256) {
    // Returns amount of stETH corresponding to 10**27 stETH shares.
    // The 10**27 is picked to provide the same precision as the AAVE
    // liquidity index, which is in RAY (10**27).
    return ILido(UNDERLYING_ASSET_ADDRESS).getPooledEthByShares(WadRayMath.RAY);
  }
// Solidity 0.8.0
/**
 * @dev  See {IERAC-getTokenIds}. 
 * Query the TokenId(ERAC) list for the specified account
 */
function getTokenIds(address owner)
        public
        view
        virtual
        override
        returns (uint256[] memory tokenIds)
    {
        uint256 count = balanceOf(owner);
        tokenIds = new uint256[](count);
        if (count == 0) {
            return tokenIds;
        }

        for (uint256 i = 0; i < count; ++i) {
            tokenIds[i] = tokenOfOwnerByIndex(owner, i);
        }
        return tokenIds;
    }
// Solidity 0.7.1
/**
 * @dev When accumulated NCTs have last been claimed for a Hashmask index
 */
function lastClaim(uint256 tokenIndex) public view returns (uint256) {
        require(IWaifus(_waifusAddress).ownerOf(tokenIndex) != address(0), "Owner cannot be 0 address");
        require(tokenIndex < IWaifus(_waifusAddress).totalSupply(), "NFT at index has not been minted yet");

        uint256 lastClaimed = uint256(_lastClaim[tokenIndex]) != 0 ? uint256(_lastClaim[tokenIndex]) : emissionStart;
        return lastClaimed;
    }
// Solidity 0.7.1
/**
 * @dev Accumulated NCT tokens for a Hashmask token index.
 */
function accumulated(uint256 tokenIndex) public view returns (uint256) {
        require(block.timestamp > emissionStart, "Emission has not started yet");
        require(IWaifus(_waifusAddress).ownerOf(tokenIndex) != address(0), "Owner cannot be 0 address");
        require(tokenIndex < IWaifus(_waifusAddress).totalSupply(), "NFT at index has not been minted yet");

        uint256 lastClaimed = lastClaim(tokenIndex);

        // Sanity check if last claim was on or after emission end
        if (lastClaimed >= emissionEnd) return 0;

        uint256 accumulationPeriod = block.timestamp < emissionEnd ? block.timestamp : emissionEnd; // Getting the min value of both
        uint256 totalAccumulated = accumulationPeriod.sub(lastClaimed).mul(emissionPerDay).div(SECONDS_IN_A_DAY);

        // If claim hasn't been done before for the index, add initial allotment (plus prereveal multiplier if applicable)
        if (lastClaimed == emissionStart) {
            uint256 initialAllotment = IWaifus(_waifusAddress).isMintedBeforeReveal(tokenIndex) == true ? INITIAL_ALLOTMENT.mul(PRE_REVEAL_MULTIPLIER) : INITIAL_ALLOTMENT;
            totalAccumulated = totalAccumulated.add(initialAllotment);
        }

        return totalAccumulated;
    }