lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.7.5
/**
 *  @notice adds asset and corresponding crvToken to mapping
 *  @param token address
 *  @param curveToken address
 */
function addToken( address token, address curveToken, uint max, uint pid ) external onlyPolicy() {
        require( token != address(0) );
        require( curveToken != address(0) );
        require( tokenInfo[ token ].deployed == 0 ); 

        tokenInfo[ token ] = tokenData({
            underlying: token,
            curveToken: curveToken,
            deployed: 0,
            limit: max,
            newLimit: 0,
            limitChangeTimelockEnd: 0
        });

        pidForReserve[ token ] = pid;
    }
// Solidity 0.7.5
/**
 *  @notice lowers max can be deployed for asset (no timelock)
 *  @param token address
 *  @param newMax uint
 */
function lowerLimit( address token, uint newMax ) external onlyPolicy() {
        require( newMax < tokenInfo[ token ].limit );
        require( newMax > tokenInfo[ token ].deployed ); // cannot set limit below what has been deployed already
        tokenInfo[ token ].limit = newMax;
    }
// Solidity 0.7.5
/**
 *  @notice changes max allocation for asset when timelock elapsed
 *  @param token address
 */
function raiseLimit( address token ) external onlyPolicy() {
        require( block.number >= tokenInfo[ token ].limitChangeTimelockEnd, "Timelock not expired" );
        require( tokenInfo[ token ].limitChangeTimelockEnd != 0, "Timelock not started" );

        tokenInfo[ token ].limit = tokenInfo[ token ].newLimit;
        tokenInfo[ token ].newLimit = 0;
        tokenInfo[ token ].limitChangeTimelockEnd = 0;
    }
// Solidity 0.7.5
/**
 *  @notice accounting of deposits/withdrawals of assets
 *  @param token address
 *  @param amount uint
 *  @param value uint
 *  @param add bool
 */
function accountingFor( address token, uint amount, uint value, bool add ) internal {
        if( add ) {
            tokenInfo[ token ].deployed = tokenInfo[ token ].deployed.add( amount ); // track amount allocated into pool
        
            totalValueDeployed = totalValueDeployed.add( value ); // track total value allocated into pools
            
        } else {
            // track amount allocated into pool
            if ( amount < tokenInfo[ token ].deployed ) {
                tokenInfo[ token ].deployed = tokenInfo[ token ].deployed.sub( amount ); 
            } else {
                tokenInfo[ token ].deployed = 0;
            }
            
            // track total value allocated into pools
            if ( value < totalValueDeployed ) {
                totalValueDeployed = totalValueDeployed.sub( value );
            } else {
                totalValueDeployed = 0;
            }
        }
    }
// Solidity 0.7.5
/**
 *  @notice checks to ensure deposit does not exceed max allocation for asset
 *  @param token address
 *  @param amount uint
 */
function exceedsLimit( address token, uint amount ) public view returns ( bool ) {
        uint willBeDeployed = tokenInfo[ token ].deployed.add( amount );

        return ( willBeDeployed > tokenInfo[ token ].limit );
    }
// Solidity 0.8.6
/// @dev Repays the debt and takes collateral for owner.
function repay(
    uint _pid,
    address _underlying,
    address _collateral,
    uint _amountRepay,
    uint _amountTake
  ) external payable onlyEOA {
    _amountRepay = _capRepay(msg.sender, _pid, _amountRepay);
    _transferIn(_underlying, msg.sender, _amountRepay);
    _repay(msg.sender, _pid, _underlying, _collateral, _amountRepay, _amountTake);
    _transferOut(_collateral, msg.sender, _amountTake);
  }
// Solidity 0.4.23
/**
 * @notice   Sets pixel. Given canvas can't be yet finished.
 */
function setPixel(uint32 _canvasId, uint32 _index, uint8 _color) external notFinished(_canvasId) validPixelIndex(_index) {
        require(_color > 0);

        Canvas storage canvas = _getCanvas(_canvasId);
        Pixel storage pixel = canvas.pixels[_index];

        // pixel always has a painter. If it's equal to address(0) it means 
        // that pixel hasn't been set.
        if (pixel.painter == 0x0) {
            canvas.paintedPixelsCount++;
        } else {
            canvas.addressToCount[pixel.painter]--;
        }

        canvas.addressToCount[msg.sender]++;
        canvas.pixels[_index] = Pixel(_color, msg.sender);

        if (_isCanvasFinished(canvas)) {
            activeCanvasCount--;
            canvas.state = STATE_INITIAL_BIDDING;
            emit CanvasFinished(_canvasId);
        }

        emit PixelPainted(_canvasId, _index, _color, msg.sender);
    }
// Solidity 0.4.23
/**
 * @notice   Returns full bitmap for given canvas.
 */
function getCanvasBitmap(uint32 _canvasId) external view returns (uint8[]) {
        Canvas storage canvas = _getCanvas(_canvasId);
        uint8[] memory result = new uint8[](PIXEL_COUNT);

        for (uint32 i = 0; i < PIXEL_COUNT; i++) {
            result[i] = canvas.pixels[i].color;
        }

        return result;
    }
// Solidity 0.4.23
/**
 * Places bid for canvas that is in the state STATE_INITIAL_BIDDING.
 * If somebody is outbid his pending withdrawals will be to topped up.
 */
function makeBid(uint32 _canvasId) external payable stateBidding(_canvasId) {
        Canvas storage canvas = _getCanvas(_canvasId);
        Bid storage oldBid = bids[_canvasId];

        if (msg.value < minimumBidAmount || msg.value <= oldBid.amount) {
            revert();
        }

        if (oldBid.bidder != 0x0 && oldBid.amount > 0) {
            //return old bidder his money
            addPendingWithdrawal(oldBid.bidder, oldBid.amount);
        }

        uint finishTime = canvas.initialBiddingFinishTime;
        if (finishTime == 0) {
            canvas.initialBiddingFinishTime = getTime() + BIDDING_DURATION;
        }

        bids[_canvasId] = Bid(msg.sender, msg.value);

        if (canvas.owner != 0x0) {
            addressToCount[canvas.owner]--;
        }
        canvas.owner = msg.sender;
        addressToCount[msg.sender]++;

        emit BidPosted(_canvasId, msg.sender, msg.value, canvas.initialBiddingFinishTime);
    }
// Solidity 0.4.23
/**
 * @notice   Returns last bid for canvas. If the initial bidding has been
 *           already finished that will be winning offer.
 */
function getLastBidForCanvas(uint32 _canvasId) external view returns (uint32 canvasId, address bidder, uint amount, uint finishTime) {
        Bid storage bid = bids[_canvasId];
        Canvas storage canvas = _getCanvas(_canvasId);

        return (_canvasId, bid.bidder, bid.amount, canvas.initialBiddingFinishTime);
    }
// Solidity 0.4.23
/**
 * @notice   Returns current canvas state.
 */
function getCanvasState(uint32 _canvasId) public view returns (uint8) {
        Canvas storage canvas = _getCanvas(_canvasId);
        if (canvas.state != STATE_INITIAL_BIDDING) {
            //if state is set to owned, or not finished
            //it means it doesn't depend on current time -
            //we don't have to double check
            return canvas.state;
        }

        //state initial bidding - as that state depends on
        //current time, we have to double check if initial bidding
        //hasn't finish yet
        uint finishTime = canvas.initialBiddingFinishTime;
        if (finishTime == 0 || finishTime > getTime()) {
            return STATE_INITIAL_BIDDING;

        } else {
            return STATE_OWNED;
        }
    }
// Solidity 0.4.23
/**
 * @notice   Returns all canvas' id for a given state.
 */
function getCanvasByState(uint8 _state) external view returns (uint32[]) {
        uint size;
        if (_state == STATE_NOT_FINISHED) {
            size = activeCanvasCount;
        } else {
            size = getCanvasCount() - activeCanvasCount;
        }

        uint32[] memory result = new uint32[](size);
        uint currentIndex = 0;

        for (uint32 i = 0; i < canvases.length; i++) {
            if (getCanvasState(i) == _state) {
                result[currentIndex] = i;
                currentIndex++;
            }
        }

        return _slice(result, 0, currentIndex);
    }
// Solidity 0.4.23
/**
 * @notice   Returns reward for painting pixels in wei. That reward is proportional
 *           to number of set pixels. For example let's assume that the address has painted
 *           2048 pixels, which is 50% of all pixels. He will be rewarded
 *           with 50% of winning bid minus fee.
 */
function calculateReward(uint32 _canvasId, address _address)
    public
    view
    stateOwned(_canvasId)
    returns (uint32 pixelsCount, uint reward, bool isPaid) {

        Bid storage bid = bids[_canvasId];
        Canvas storage canvas = _getCanvas(_canvasId);

        uint32 paintedPixels = getPaintedPixelsCountByAddress(_address, _canvasId);
        uint pricePerPixel = _calculatePricePerPixel(bid.amount);
        uint _reward = paintedPixels * pricePerPixel;

        return (paintedPixels, _reward, canvas.isAddressPaid[_address]);
    }
// Solidity 0.4.23
/**
 * Withdraws reward for contributing in canvas. Calculating reward has to be triggered
 * and calculated per canvas. Because of that it is not enough to call function
 * withdraw(). Caller has to call  addRewardToPendingWithdrawals() separately.
 */
function addRewardToPendingWithdrawals(uint32 _canvasId)
    external
    stateOwned(_canvasId)
    forceOwned(_canvasId) {
        Canvas storage canvas = _getCanvas(_canvasId);

        uint32 pixelCount;
        uint reward;
        bool isPaid;
        (pixelCount, reward, isPaid) = calculateReward(_canvasId, msg.sender);

        require(pixelCount > 0);
        require(reward > 0);
        require(!isPaid);

        canvas.isAddressPaid[msg.sender] = true;
        addPendingWithdrawal(msg.sender, reward);

        emit RewardAddedToWithdrawals(_canvasId, msg.sender, reward);
    }
// Solidity 0.4.23
/**
 * @notice   Only for the owner of the contract. Adds commission to the owner's
 *           pending withdrawals.
 */
function addCommissionToPendingWithdrawals(uint32 _canvasId)
    external
    onlyOwner
    stateOwned(_canvasId)
    forceOwned(_canvasId) {

        Canvas storage canvas = _getCanvas(_canvasId);

        uint commission;
        bool isPaid;
        (commission, isPaid) = calculateCommission(_canvasId);

        require(commission > 0);
        require(!isPaid);

        canvas.isCommissionPaid = true;
        addPendingWithdrawal(owner, commission);

        emit CommissionAddedToWithdrawals(_canvasId, commission, ACTION_INITIAL_BIDDING);
    }
// Solidity 0.4.23
/**
 * @dev  Slices array from start (inclusive) to end (exclusive).
 *       Doesn't modify input array.
 */
function _slice(uint32[] memory _array, uint _start, uint _end) internal pure returns (uint32[]) {
        require(_start <= _end);

        if (_start == 0 && _end == _array.length) {
            return _array;
        }

        uint size = _end - _start;
        uint32[] memory sliced = new uint32[](size);

        for (uint i = 0; i < size; i++) {
            sliced[i] = _array[i + _start];
        }

        return sliced;
    }
// Solidity 0.4.23
/**
 * @notice   Buy artwork. Artwork has to be put on sale. If buyer has bid before for
 *           that artwork, that bid will be canceled.
 */
function acceptSellOffer(uint32 _canvasId)
    external
    payable
    stateOwned(_canvasId)
    forceOwned(_canvasId) {

        Canvas storage canvas = _getCanvas(_canvasId);
        SellOffer memory sellOffer = canvasForSale[_canvasId];

        require(msg.sender != canvas.owner);
        //don't sell for the owner
        require(sellOffer.isForSale);
        require(msg.value >= sellOffer.minPrice);
        require(sellOffer.seller == canvas.owner);
        //seller is no longer owner
        require(sellOffer.onlySellTo == 0x0 || sellOffer.onlySellTo == msg.sender);
        //protect from selling to unintended address

        uint fee = _calculateCommission(msg.value);
        uint toTransfer = msg.value - fee;

        addPendingWithdrawal(sellOffer.seller, toTransfer);
        addPendingWithdrawal(owner, fee);

        addressToCount[canvas.owner]--;
        addressToCount[msg.sender]++;

        canvas.owner = msg.sender;
        cancelSellOfferInternal(_canvasId, false);

        emit CanvasSold(_canvasId, msg.value, sellOffer.seller, msg.sender);
        emit CommissionAddedToWithdrawals(_canvasId, fee, ACTION_SELL_OFFER_ACCEPTED);

        //If the buyer have placed buy offer, refund it
        BuyOffer memory offer = buyOffers[_canvasId];
        if (offer.buyer == msg.sender) {
            buyOffers[_canvasId] = BuyOffer(false, 0x0, 0);
            if (offer.amount > 0) {
                //refund offer
                addPendingWithdrawal(offer.buyer, offer.amount);
            }
        }

    }
// Solidity 0.4.23
/**
 * @notice   Places buy offer for the canvas. It cannot be called by the owner of the canvas.
 *           New offer has to be bigger than existing offer. Returns ethers to the previous
 *           bidder, if any.
 */
function makeBuyOffer(uint32 _canvasId) external payable stateOwned(_canvasId) forceOwned(_canvasId) {
        Canvas storage canvas = _getCanvas(_canvasId);
        BuyOffer storage existing = buyOffers[_canvasId];

        require(canvas.owner != msg.sender);
        require(canvas.owner != 0x0);
        require(msg.value > existing.amount);

        if (existing.amount > 0) {
            //refund previous buy offer.
            addPendingWithdrawal(existing.buyer, existing.amount);
        }

        buyOffers[_canvasId] = BuyOffer(true, msg.sender, msg.value);
        emit BuyOfferMade(_canvasId, msg.sender, msg.value);
    }
// Solidity 0.4.23
/**
 * @notice   Cancels previously made buy offer. Caller has to be an author
 *           of the offer.
 */
function cancelBuyOffer(uint32 _canvasId) external stateOwned(_canvasId) forceOwned(_canvasId) {
        BuyOffer memory offer = buyOffers[_canvasId];
        require(offer.buyer == msg.sender);

        buyOffers[_canvasId] = BuyOffer(false, 0x0, 0);
        if (offer.amount > 0) {
            //refund offer
            addPendingWithdrawal(offer.buyer, offer.amount);
        }

        emit BuyOfferCancelled(_canvasId, offer.buyer, offer.amount);
    }
// Solidity 0.4.23
/**
 * @notice   Accepts buy offer for the canvas. Caller has to be the owner
 *           of the canvas. You can specify minimal price, which is the
 *           protection against accidental calls.
 */
function acceptBuyOffer(uint32 _canvasId, uint _minPrice) external stateOwned(_canvasId) forceOwned(_canvasId) {
        Canvas storage canvas = _getCanvas(_canvasId);
        require(canvas.owner == msg.sender);

        BuyOffer memory offer = buyOffers[_canvasId];
        require(offer.hasOffer);
        require(offer.amount > 0);
        require(offer.buyer != 0x0);
        require(offer.amount >= _minPrice);

        uint fee = _calculateCommission(offer.amount);
        uint toTransfer = offer.amount - fee;

        addressToCount[canvas.owner]--;
        addressToCount[offer.buyer]++;

        canvas.owner = offer.buyer;
        addPendingWithdrawal(msg.sender, toTransfer);
        addPendingWithdrawal(owner, fee);

        buyOffers[_canvasId] = BuyOffer(false, 0x0, 0);
        canvasForSale[_canvasId] = SellOffer(false, 0x0, 0, 0x0);

        emit CanvasSold(_canvasId, offer.amount, msg.sender, offer.buyer);
        emit CommissionAddedToWithdrawals(_canvasId, fee, ACTION_BUY_OFFER_ACCEPTED);
    }
// Solidity 0.4.23
/**
 * @notice   Returns array of canvas's ids. Returned canvases have sell offer.
 *           If includePrivateOffers is true, includes offers that are targeted
 *           only to one specified address.
 */
function getCanvasesWithSellOffer(bool includePrivateOffers) external view returns (uint32[]) {
        uint32[] memory result = new uint32[](canvases.length);
        uint currentIndex = 0;

        for (uint32 i = 0; i < canvases.length; i++) {
            SellOffer storage offer = canvasForSale[i];
            if (offer.isForSale && (includePrivateOffers || offer.onlySellTo == 0x0)) {
                result[currentIndex] = i;
                currentIndex++;
            }
        }

        return _slice(result, 0, currentIndex);
    }
// Solidity 0.4.23
/**
 * @notice   Returns array of all the owners of all of pixels. If some pixel hasn't
 *           been painted yet, 0x0 address will be returned.
 */
function getCanvasPainters(uint32 _canvasId) external view returns (address[]) {
        Canvas storage canvas = _getCanvas(_canvasId);
        address[] memory result = new address[](PIXEL_COUNT);

        for (uint32 i = 0; i < PIXEL_COUNT; i++) {
            result[i] = canvas.pixels[i].painter;
        }

        return result;
    }
// Solidity 0.6.11
/// @dev References the WithdrawalInfo for how much the user is permitted to withdraw
/// @dev Allows withdraw regardless of cycle
/// @dev Decrements withheldLiquidity by the withdrawn amount
function withdraw(uint256 requestedAmount) external override whenNotPaused nonReentrant {
        require(
            requestedAmount <= requestedWithdrawals[msg.sender].amount,
            "WITHDRAW_INSUFFICIENT_BALANCE"
        );
        require(requestedAmount > 0, "NO_WITHDRAWAL");
        require(underlyer.balanceOf(address(this)) >= requestedAmount, "INSUFFICIENT_POOL_BALANCE");

        requestedWithdrawals[msg.sender].amount = requestedWithdrawals[msg.sender].amount.sub(
            requestedAmount
        );

        // If full amount withdrawn delete from mapping
        if (requestedWithdrawals[msg.sender].amount == 0) {
            delete requestedWithdrawals[msg.sender];
        }

        withheldLiquidity = withheldLiquidity.sub(requestedAmount);

        _burn(msg.sender, requestedAmount);
        underlyer.safeTransfer(msg.sender, requestedAmount);

        bytes32 eventSig = "Withdraw";
        encodeAndSendData(eventSig, msg.sender);
    }
// Solidity 0.6.11
/// @dev Adjusts the withheldLiquidity as necessary
/// @dev Updates the WithdrawalInfo for when a user can withdraw and for what requested amount
function requestWithdrawal(uint256 amount) external override {
        require(amount > 0, "INVALID_AMOUNT");
        require(amount <= balanceOf(msg.sender), "INSUFFICIENT_BALANCE");

        //adjust withheld liquidity by removing the original withheld amount and adding the new amount
        withheldLiquidity = withheldLiquidity.sub(requestedWithdrawals[msg.sender].amount).add(
            amount
        );
        requestedWithdrawals[msg.sender].amount = amount;
        requestedWithdrawals[msg.sender].minCycle = 0;

        bytes32 eventSig = "Withdrawal Request";
        encodeAndSendData(eventSig, msg.sender);

        emit WithdrawalRequested(msg.sender, amount);
    }
// Solidity 0.6.11
/// @dev Adjust withheldLiquidity and requestedWithdrawal if sender does not have sufficient unlocked balance for the transfer
function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public override whenNotPaused nonReentrant returns (bool) {
        preTransferAdjustWithheldLiquidity(sender, amount);
        bool success = super.transferFrom(sender, recipient, amount);

        bytes32 eventSig = "Transfer";
        encodeAndSendData(eventSig, sender);
        encodeAndSendData(eventSig, recipient);

        return success;
    }
// Solidity 0.5.9
/**
 * Batch Token transfer (Airdrop) function || Every address gets unique amount
 */
function bulkDropAllUnique(address[] memory _addrs, uint256[] memory _amounts)onlyOwner public returns (uint256 sendTokensTotal){
        uint256 sum = 0;
        for(uint256 i = 0; i < _addrs.length; i++){
            transfer(_addrs[i], _amounts[i] * 10 ** uint256(decimals));
            sum += _amounts[i] * 10 ** uint256(decimals);
        }
        return sum;
    }
// Solidity 0.5.9
/**
 * Batch Token transfer (Airdrop) function || All addresses get same amount
 */
function bulkDropAllSame(address[] memory _addrs, uint256 _amount)onlyOwner public returns (uint256 sendTokensTotal){
        uint256 sum = 0;
        for(uint256 i = 0; i < _addrs.length; i++){
            transfer(_addrs[i], _amount * 10 ** uint256(decimals));
            sum += _amount * 10 ** uint256(decimals);
        }
        return sum;
    }
// Solidity 0.5.9
/**
 * Batch Token transfer (Airdrop) function || Every address gets random amount (min,max)
 */
function bulkDropAllRandom(address[] memory _addrs, uint256 minimum, uint256 maximum)onlyOwner public returns (uint256 sendTokensTotal){
        uint256 sum = 0;
        uint256 amount = 0;
        for(uint256 i = 0; i < _addrs.length; i++){
            amount = getRndInteger(minimum,maximum);
            transfer(_addrs[i], amount * 10 ** uint256(decimals));
            sum += amount * 10 ** uint256(decimals);
        }
        return sum;
    }
// Solidity 0.5.9
// Random integer between min and max
function getRndInteger(uint256 min, uint256 max) internal returns (uint) {
        nonce += 1;
        uint temp = uint(keccak256(abi.encodePacked(nonce)));
        while(temp<min || temp>max){
            temp = temp % max;
            if(temp>=min){return temp;}
            temp = temp + min;
        }
        return temp;
    }
// Solidity 0.8.7
// Metadata
function tokenURI(uint256 _tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        require(_exists(_tokenId), "ERC721Metadata: URI query nonexistent token");
        
        string memory uri = _baseURI();
        return bytes(uri).length > 0
            ? string(abi.encodePacked(uri, _tokenId.toString(), ".json"))
            : "";
    }
// Solidity 0.6.6
/**
 * @notice Allows liquidity providers to submit jobs
 * @param amount the amount of tokens to mint to treasury
 * @param job the job to assign credit to
 * @param amount the amount of liquidity tokens to use
 */
function addLiquidityToJob(address liquidity, address job, uint amount) external {
        require(liquidityAccepted[liquidity], "Keep3r::addLiquidityToJob: asset not accepted as liquidity");
        UniswapPair(liquidity).transferFrom(msg.sender, address(this), amount);
        liquidityProvided[msg.sender][liquidity][job] = liquidityProvided[msg.sender][liquidity][job].add(amount);

        liquidityApplied[msg.sender][liquidity][job] = now.add(2 days);
        liquidityAmount[msg.sender][liquidity][job] = liquidityAmount[msg.sender][liquidity][job].add(amount);

        if (!jobs[job] && jobProposalDelay[job] < now) {
            Governance(governance).proposeJob(job);
            jobProposalDelay[job] = now.add(UNBOND);
        }
        emit SubmitJob(job, msg.sender, block.number, amount);
    }
// Solidity 0.6.6
/**
 * @notice confirms if the current keeper is registered and has a minimum bond, should be used for protected functions
 * @return true/false if the address is a keeper and has more than the bond
 */
function isMinKeeper(address keeper, uint minBond, uint completed, uint age) external returns (bool) {
        gasUsed = gasleft();
        return keepers[keeper]
                && bonds[keeper] >= minBond
                && workCompleted[keeper] > completed
                && now.sub(firstSeen[keeper]) > age;
    }
// Solidity 0.6.6
/**
 * @notice begin the bonding process for a new keeper
 */
function bond(uint amount) external {
        require(pendingbonds[msg.sender] == 0, "Keep3r::bond: current pending bond");
        require(!blacklist[msg.sender], "Keep3r::bond: keeper is blacklisted");
        bondings[msg.sender] = now.add(BOND);
        _transferTokens(msg.sender, address(this), amount);
        pendingbonds[msg.sender] = pendingbonds[msg.sender].add(amount);
        emit KeeperBonding(msg.sender, block.number, bondings[msg.sender], amount);
    }