lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @notice Exit a pool - redeem pool tokens for underlying assets
 * @param self - ConfigurableRightsPool instance calling the library
 * @param bPool - Core BPool the CRP is wrapping
 * @param poolAmountIn - amount of pool tokens to redeem
 * @param minAmountsOut - minimum amount of asset tokens to receive
 * @return exitFee - calculated exit fee
 * @return pAiAfterExitFee - final amount in (after accounting for exit fee)
 * @return actualAmountsOut - calculated amounts of each token to pull
 */
function exitPool(
        IConfigurableRightsPool self,
        IBPool bPool,
        uint poolAmountIn,
        uint[] calldata minAmountsOut
    )
        external
        view
        returns (uint exitFee, uint pAiAfterExitFee, uint[] memory actualAmountsOut)
    {
        address[] memory tokens = bPool.getCurrentTokens();

        require(minAmountsOut.length == tokens.length, "ERR_AMOUNTS_MISMATCH");

        uint poolTotal = self.totalSupply();

        // Calculate exit fee and the final amount in
        exitFee = BalancerSafeMath.bmul(poolAmountIn, BalancerConstants.EXIT_FEE);
        pAiAfterExitFee = BalancerSafeMath.bsub(poolAmountIn, exitFee);

        uint ratio = BalancerSafeMath.bdiv(pAiAfterExitFee,
                                           BalancerSafeMath.badd(poolTotal, 1));

        require(ratio != 0, "ERR_MATH_APPROX");

        actualAmountsOut = new uint[](tokens.length);

        // This loop contains external calls
        // External calls are to math libraries or the underlying pool, so low risk
        for (uint i = 0; i < tokens.length; i++) {
            address t = tokens[i];
            uint bal = bPool.getBalance(t);
            // Subtract 1 to ensure any rounding errors favor the pool
            uint tokenAmountOut = BalancerSafeMath.bmul(ratio,
                                                        BalancerSafeMath.bsub(bal, 1));

            require(tokenAmountOut != 0, "ERR_MATH_APPROX");
            require(tokenAmountOut >= minAmountsOut[i], "ERR_LIMIT_OUT");

            actualAmountsOut[i] = tokenAmountOut;
        }
    }
// Solidity 0.6.12
/**
 * @notice Join by swapping a fixed amount of an external token in (must be present in the pool)
 *         System calculates the pool token amount
 * @param self - ConfigurableRightsPool instance calling the library
 * @param bPool - Core BPool the CRP is wrapping
 * @param tokenIn - which token we're transferring in
 * @param tokenAmountIn - amount of deposit
 * @param minPoolAmountOut - minimum of pool tokens to receive
 * @return poolAmountOut - amount of pool tokens minted and transferred
 */
function joinswapExternAmountIn(
        IConfigurableRightsPool self,
        IBPool bPool,
        address tokenIn,
        uint tokenAmountIn,
        uint minPoolAmountOut
    )
        external
        view
        returns (uint poolAmountOut)
    {
        require(bPool.isBound(tokenIn), "ERR_NOT_BOUND");
        require(tokenAmountIn <= BalancerSafeMath.bmul(bPool.getBalance(tokenIn),
                                                       BalancerConstants.MAX_IN_RATIO),
                                                       "ERR_MAX_IN_RATIO");

        poolAmountOut = bPool.calcPoolOutGivenSingleIn(
                            bPool.getBalance(tokenIn),
                            bPool.getDenormalizedWeight(tokenIn),
                            self.totalSupply(),
                            bPool.getTotalDenormalizedWeight(),
                            tokenAmountIn,
                            bPool.getSwapFee()
                        );

        require(poolAmountOut >= minPoolAmountOut, "ERR_LIMIT_OUT");
    }
// Solidity 0.6.12
/**
 * @notice Join by swapping an external token in (must be present in the pool)
 *         To receive an exact amount of pool tokens out. System calculates the deposit amount
 * @param self - ConfigurableRightsPool instance calling the library
 * @param bPool - Core BPool the CRP is wrapping
 * @param tokenIn - which token we're transferring in (system calculates amount required)
 * @param poolAmountOut - amount of pool tokens to be received
 * @param maxAmountIn - Maximum asset tokens that can be pulled to pay for the pool tokens
 * @return tokenAmountIn - amount of asset tokens transferred in to purchase the pool tokens
 */
function joinswapPoolAmountOut(
        IConfigurableRightsPool self,
        IBPool bPool,
        address tokenIn,
        uint poolAmountOut,
        uint maxAmountIn
    )
        external
        view
        returns (uint tokenAmountIn)
    {
        require(bPool.isBound(tokenIn), "ERR_NOT_BOUND");

        tokenAmountIn = bPool.calcSingleInGivenPoolOut(
                            bPool.getBalance(tokenIn),
                            bPool.getDenormalizedWeight(tokenIn),
                            self.totalSupply(),
                            bPool.getTotalDenormalizedWeight(),
                            poolAmountOut,
                            bPool.getSwapFee()
                        );

        require(tokenAmountIn != 0, "ERR_MATH_APPROX");
        require(tokenAmountIn <= maxAmountIn, "ERR_LIMIT_IN");

        require(tokenAmountIn <= BalancerSafeMath.bmul(bPool.getBalance(tokenIn),
                                                       BalancerConstants.MAX_IN_RATIO),
                                                       "ERR_MAX_IN_RATIO");
    }
// Solidity 0.6.12
/**
 * @notice Exit a pool - redeem a specific number of pool tokens for an underlying asset
 *         Asset must be present in the pool, and will incur an EXIT_FEE (if set to non-zero)
 * @param self - ConfigurableRightsPool instance calling the library
 * @param bPool - Core BPool the CRP is wrapping
 * @param tokenOut - which token the caller wants to receive
 * @param poolAmountIn - amount of pool tokens to redeem
 * @param minAmountOut - minimum asset tokens to receive
 * @return exitFee - calculated exit fee
 * @return tokenAmountOut - amount of asset tokens returned
 */
function exitswapPoolAmountIn(
        IConfigurableRightsPool self,
        IBPool bPool,
        address tokenOut,
        uint poolAmountIn,
        uint minAmountOut
    )
        external
        view
        returns (uint exitFee, uint tokenAmountOut)
    {
        require(bPool.isBound(tokenOut), "ERR_NOT_BOUND");

        tokenAmountOut = bPool.calcSingleOutGivenPoolIn(
                            bPool.getBalance(tokenOut),
                            bPool.getDenormalizedWeight(tokenOut),
                            self.totalSupply(),
                            bPool.getTotalDenormalizedWeight(),
                            poolAmountIn,
                            bPool.getSwapFee()
                        );

        require(tokenAmountOut >= minAmountOut, "ERR_LIMIT_OUT");
        require(tokenAmountOut <= BalancerSafeMath.bmul(bPool.getBalance(tokenOut),
                                                        BalancerConstants.MAX_OUT_RATIO),
                                                        "ERR_MAX_OUT_RATIO");

        exitFee = BalancerSafeMath.bmul(poolAmountIn, BalancerConstants.EXIT_FEE);
    }
// Solidity 0.6.12
/**
 * @notice Exit a pool - redeem pool tokens for a specific amount of underlying assets
 *         Asset must be present in the pool
 * @param self - ConfigurableRightsPool instance calling the library
 * @param bPool - Core BPool the CRP is wrapping
 * @param tokenOut - which token the caller wants to receive
 * @param tokenAmountOut - amount of underlying asset tokens to receive
 * @param maxPoolAmountIn - maximum pool tokens to be redeemed
 * @return exitFee - calculated exit fee
 * @return poolAmountIn - amount of pool tokens redeemed
 */
function exitswapExternAmountOut(
        IConfigurableRightsPool self,
        IBPool bPool,
        address tokenOut,
        uint tokenAmountOut,
        uint maxPoolAmountIn
    )
        external
        view
        returns (uint exitFee, uint poolAmountIn)
    {
        require(bPool.isBound(tokenOut), "ERR_NOT_BOUND");
        require(tokenAmountOut <= BalancerSafeMath.bmul(bPool.getBalance(tokenOut),
                                                        BalancerConstants.MAX_OUT_RATIO),
                                                        "ERR_MAX_OUT_RATIO");
        poolAmountIn = bPool.calcPoolInGivenSingleOut(
                            bPool.getBalance(tokenOut),
                            bPool.getDenormalizedWeight(tokenOut),
                            self.totalSupply(),
                            bPool.getTotalDenormalizedWeight(),
                            tokenAmountOut,
                            bPool.getSwapFee()
                        );

        require(poolAmountIn != 0, "ERR_MATH_APPROX");
        require(poolAmountIn <= maxPoolAmountIn, "ERR_LIMIT_IN");

        exitFee = BalancerSafeMath.bmul(poolAmountIn, BalancerConstants.EXIT_FEE);
    }
// Solidity 0.8.7
// Calculated based on % of total vote supply at snapshotId, multiplied by amount available, minus claimed
function claimable(uint snapshotId, address user) public view returns (uint) {
        IVoters voters = IVoters(dao.voters());
        uint total = snapshotAmounts[snapshotId];
        uint totalSupply = voters.totalSupplyAt(snapshotId);
        uint balance = voters.balanceOfAt(user, snapshotId);
        require(totalSupply > 0, "totalSupply = 0");
        return ((total * balance) / totalSupply) - claimedAmounts[snapshotId][user];
    }
// Solidity 0.8.9
// Update minimum tokens accumulated on the contract before a swap is performed
function updateMinTokensBeforeSwap(uint256 newAmount) external onlyOwner {
        uint256 circulatingTokens = _totalTokens - balanceOf(_deadAddress);

        uint256 maxTokensBeforeSwap = circulatingTokens / 110;
        uint256 newMinTokensBeforeSwap = newAmount * 10**9;

        require(newMinTokensBeforeSwap < maxTokensBeforeSwap, "Amount must be less than 1 percent of the circulating supply");
        _minTokensBeforeSwap = newMinTokensBeforeSwap;
    }
// Solidity 0.8.9
// If there is a PCS upgrade then add the ability to change the router and pairs to the new version
function changeRouterVersion(address _router) public onlyOwner returns (address) {
        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(_router);

        address newPair = IUniswapV2Factory(_uniswapV2Router.factory()).getPair(address(this), _uniswapV2Router.WETH());
        if(newPair == address(0)){
            // Pair doesn't exist
            newPair = IUniswapV2Factory(_uniswapV2Router.factory())
            .createPair(address(this), _uniswapV2Router.WETH());
        }
        // Set the new pair
        uniswapV2Pair = newPair;

        // Set the router of the contract variables
        uniswapV2Router = _uniswapV2Router;

        return newPair;
    }
// Solidity 0.8.9
// Check all transactions and group transactions older than 21 days into their own bucket
function _aggregateOldTransactions(address sender) private {
        uint256 totalBlockTimes = _timedTransactionsMap[sender].txBlockTimes.length;

        if (totalBlockTimes < 1) {
            return;
        }

        uint256 oldestBlockTime = block.timestamp - _gate2Time;

        // If the first transaction is not yet 21 days old then do not aggregate
        if (_timedTransactionsMap[sender].txBlockTimes[0] > oldestBlockTime) {
            return;
        }

        uint lastAggregateIndex = 0;
        uint256 totalTokens = 0;
        for (uint i = 0; i < totalBlockTimes; i++) {
            uint256 txBlockTime = _timedTransactionsMap[sender].txBlockTimes[i];

            if (txBlockTime > oldestBlockTime) {
                break;
            }

            totalTokens = totalTokens + _timedTransactionsMap[sender].timedTxAmount[txBlockTime];
            lastAggregateIndex = i;
        }

        _sliceBlockTimeArray(sender, lastAggregateIndex);

        _timedTransactionsMap[sender].txBlockTimes[0] = OVER_21_DAYS_BLOCK_TIME;
        _timedTransactionsMap[sender].timedTxAmount[OVER_21_DAYS_BLOCK_TIME] = totalTokens;
    }
// Solidity 0.8.9
// _sliceBlockTimeArray removes elements before the provided index from the transaction block
// time array for the given account. This is in order to keep an ordered list of transaction block
// times.
function _sliceBlockTimeArray(address account, uint indexFrom) private {
        uint oldArrayLength = _timedTransactionsMap[account].txBlockTimes.length;

        if (indexFrom <= 0) return;

        if (indexFrom >= oldArrayLength) {
            while (_timedTransactionsMap[account].txBlockTimes.length != 0) {
                _timedTransactionsMap[account].txBlockTimes.pop();
            }
            return;
        }

        uint newArrayLength = oldArrayLength - indexFrom;

        uint counter = 0;
        for (uint i = indexFrom; i < oldArrayLength; i++) {
            _timedTransactionsMap[account].txBlockTimes[counter] = _timedTransactionsMap[account].txBlockTimes[i];
            counter++;
        }

        while (newArrayLength != _timedTransactionsMap[account].txBlockTimes.length) {
            _timedTransactionsMap[account].txBlockTimes.pop();
        }
    }
// Solidity 0.5.10
/**
 * @dev See `IERC777.operatorSend`.
 *
 * Emits `Sent` and `Transfer` events.
 */
function operatorSend(
        address sender,
        address recipient,
        uint256 amount,
        bytes memory data,
        bytes memory operatorData
    )
    public
    {
        require(isOperatorFor(msg.sender, sender), "ERC777: caller is not an operator for holder");
        _send(msg.sender, sender, recipient, amount, data, operatorData, true);
    }
// Solidity 0.4.25
/**
 * add new hodl safe (ERC20 token)
 */
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
        require(tokenAddress != 0x0);
        require(amount > 0);
          
        ERC20Interface token = ERC20Interface(tokenAddress);
        
        require(token.transferFrom(msg.sender, address(this), amount));
        
        _userSafes[msg.sender].push(_currentIndex);
        _safes[_currentIndex] = Safe(_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol());
        
        _totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
        
        _currentIndex++;
        _countSafes++;
        
        emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
    }
// Solidity 0.4.25
/**
 * store comission from unfinished hodl
 */
function StoreComission(address tokenAddress, uint256 amount) private {
            
        _systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
        
        bool isNew = true;
        for(uint256 i = 0; i < _listedReserves.length; i++) {
            if(_listedReserves[i] == tokenAddress) {
                isNew = false;
                break;
            }
        }         
        if(isNew) _listedReserves.push(tokenAddress); 
    }
// Solidity 0.4.25
/**
 * delete safe values in storage
 */
function DeleteSafe(Safe s) private {
        
        _totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
        delete _safes[s.id];
        
        uint256[] storage vector = _userSafes[msg.sender];
        uint256 size = vector.length; 
        for(uint256 i = 0; i < size; i++) {
            if(vector[i] == s.id) {
                vector[i] = vector[size-1];
                vector.length--;
                break;
            }
        } 
    }
// Solidity 0.4.25
/**
 * Get user's any token balance
 */
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
        require(tokenAddress != 0x0);
        
        for(uint256 i = 1; i < _currentIndex; i++) {            
            Safe storage s = _safes[i];
            if(s.user == msg.sender && s.tokenAddress == tokenAddress)
                balance += s.amount;
        }
        return balance;
    }
// Solidity 0.4.25
/**
 * owner: withdraw all eth and all tokens fees
 */
function WithdrawAllFees() onlyOwner public {
        
        // ether
        uint256 x = _systemReserves[0x0];
        if(x > 0 && x <= address(this).balance) {
            _systemReserves[0x0] = 0;
            msg.sender.transfer(_systemReserves[0x0]);
        }
        
        // tokens
        address ta;
        ERC20Interface token;
        for(uint256 i = 0; i < _listedReserves.length; i++) {
            ta = _listedReserves[i];
            if(_systemReserves[ta] > 0)
            { 
                x = _systemReserves[ta];
                _systemReserves[ta] = 0;
                
                token = ERC20Interface(ta);
                token.transfer(msg.sender, x);
            }
        }
        _listedReserves.length = 0; 
    }
// Solidity 0.4.22
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address from where tokens are withdrawn.
/// @param _to Address to where tokens are sent.
/// @param _value Number of tokens to transfer.
/// @return Returns success of function call.
function transferFrom(address _from, address _to, uint256 _value)
        public
        returns (bool)
    {
        if (balances[_from] < _value || allowed[_from][msg.sender] < _value) {
            // Balance or allowance too low
            revert();
        }
        balances[_to] += _value;
        balances[_from] -= _value;
        allowed[_from][msg.sender] -= _value;
        emit Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.4.22
/// @dev Contract constructor function gives tokens to presale_addresses and leave 100k tokens for sale.
/// @param presale_addresses Array of addresses receiving preassigned tokens.
/// @param tokens Array of preassigned token amounts.
/// NB: Max 4 presale_addresses
function SolarNA(address[] presale_addresses, uint[] tokens)
        public
    {
        uint assignedTokens;
        owner = msg.sender;
        maxSupply = 500000 * 10**3;
        for (uint i=0; i<presale_addresses.length; i++) {
            if (presale_addresses[i] == 0) {
                // Address should not be null.
                revert();
            }
            balances[presale_addresses[i]] += tokens[i];
            assignedTokens += tokens[i];
            emit Transfer(0, presale_addresses[i], tokens[i]); // emit an event
        }
        /// If presale_addresses > 4 => The maxSupply will increase
        remaining = maxSupply - assignedTokens;
        assignedTokens += remaining;
        if (assignedTokens != maxSupply) {
            revert();
        }
    }
// Solidity 0.8.9
//@dev customer registration function. Checks if customer exist first then adds to customers array. otherwai
function register() public payable {
        require(msg.value >= registrationFee, "Insufficient funds sent");
        require(
            UserRegistion[msg.sender].isPaid == false,
            "You already registered you knucklehead"
        );

        if (UserRegistion[msg.sender].expirationDate == 0) {
            addressList.push(msg.sender);
            UserRegistion[msg.sender].isPaid = true;
            UserRegistion[msg.sender].expirationDate =
                block.timestamp +
                365 days;
        }

        if (
            UserRegistion[msg.sender].expirationDate > block.timestamp &&
            UserRegistion[msg.sender].isPaid == false
        ) {
            UserRegistion[msg.sender].isPaid = true;
            UserRegistion[msg.sender].expirationDate =
                block.timestamp +
                365 days;
        }
    }
// Solidity 0.8.11
/// @dev Function to summon minion and configure with a new safe and a dao
function summonDaoMinionAndSafe(
        // address _summoner,
        uint256 _saltNonce,
        uint256 _periodDuration,
        uint256 _votingPeriodLength,
        uint256 _gracePeriodLength,
        address[] calldata _approvedTokens, // TODO: should this just be the native wrapper
        string calldata details
    ) external returns (address _moloch, address _minion) {
        // Deploy new minion but do not set it up yet

        _moloch = daoSummoner.summonMoloch(
            msg.sender, // summoner TODO: do we still need this
            address(this), // _shaman,
            _approvedTokens,
            _periodDuration,
            _votingPeriodLength,
            _gracePeriodLength,
            0, // deposit
            3, // dillution bound
            0 // reward
        );

        _minion = minionSummoner.summonMinionAndSafe(
            _moloch,
            details,
            0,
            _saltNonce
        );

        IMINION minionContract = IMINION(_minion);

        daoIdx = daoIdx + 1;
        daos[daoIdx] = DSM(
            msg.sender,
            _moloch,
            _minion,
            minionContract.avatar(),
            false
        );

        emit SummonComplete(
            msg.sender,
            _moloch,
            _minion,
            minionContract.avatar(),
            details
        );
    }
// Solidity 0.4.18
/**
 * Constructor for a crowdsale of QuantstampToken tokens.
 *
 * @param ifSuccessfulSendTo            the beneficiary of the fund
 * @param fundingCapInEthers            the cap (maximum) size of the fund
 * @param minimumContributionInWei      minimum contribution (in wei)
 * @param start                         the start time (UNIX timestamp)
 * @param durationInMinutes             the duration of the crowdsale in minutes
 */
function QuantstampSale(
        address ifSuccessfulSendTo,
        uint fundingCapInEthers,
        uint minimumContributionInWei,
        uint start,
        uint durationInMinutes
        // address addressOfTokenUsedAsReward
    ) {
        require(ifSuccessfulSendTo != address(0) && ifSuccessfulSendTo != address(this));
        //require(addressOfTokenUsedAsReward != address(0) && addressOfTokenUsedAsReward != address(this));
        require(durationInMinutes > 0);
        beneficiary = ifSuccessfulSendTo;
        fundingCap = fundingCapInEthers * 1 ether;
        minContribution = minimumContributionInWei;
        startTime = start;
        endTime = start + (durationInMinutes * 1 minutes);
        // tokenReward = QuantstampToken(addressOfTokenUsedAsReward);
    }