lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.12
// TODO: test me
function mintDai(
        // User params
        uint256     _dart,
        bytes calldata _btcAddr,
        uint256 _minWbtcAmount,

        // Darknode params
        uint256        _amount, // Amount of renBTC.
        bytes32        _nHash,  // Nonce hash.
        bytes calldata _sig     // Minting signature. TODO: understand better
    ) external {
        // Finish the lock-and-mint cross-chain transaction using the minting
        // signature produced by RenVM.
        
        // TODO: read the IGateway code
        uint256 amount = registry.getGatewayBySymbol("BTC").mint(
            keccak256(abi.encode(msg.sender, _dart, _btcAddr, _minWbtcAmount)), 
            _amount, 
            _nHash, 
            _sig
        );
        
        // Get price
        uint256 proceeds = exchange.get_dy(0, 1, amount);
        
        // Price is OK
        if (proceeds >= _minWbtcAmount) {
            uint256 startWbtcBalance = wbtc.balanceOf(address(this));
            exchange.exchange(0, 1, amount, _minWbtcAmount);
            uint256 wbtcBought = wbtc.balanceOf(address(this)).sub(startWbtcBalance);

            require(
                wbtc.transfer(address(directProxy), wbtcBought),
                "err: transfer failed"
            );

            directProxy.borrow(
                msg.sender,
                int(wbtcBought * (10 ** 10)),
                int(_dart)
            );

            btcAddrs[msg.sender] = _btcAddr;
        } else {
            // Send renBTC to the User instead
            renbtc.transfer(msg.sender, amount);
        }
    }
// Solidity 0.8.10
/**
 * adds Galleons and Pirates to the Fleet and Sea
 * @param account the address of the staker
 * @param tokenIds the IDs of the Galleons and Pirates to stake
 */
function addManyToFleet(address account, uint16[] calldata tokenIds) external override 
        nonReentrant 
        onlyEOA
    {
        require(account == tx.origin, "account to sender mismatch");
        for (uint i = 0; i < tokenIds.length; i++) {
            if (_msgSender() != address(pirateGame)) { // dont do this step if its a mint + stake
                require(nftContract.ownerOf(tokenIds[i]) == _msgSender(), "You don't own this token");
                nftContract.transferFrom(_msgSender(), address(this), tokenIds[i]);
            } else if (tokenIds[i] == 0) {
                continue; // there may be gaps in the array for stolen tokens
            }

            if (nftContract.isGalleon(tokenIds[i])) 
                _addGalleonToFleet(account, tokenIds[i]);
            else 
                _addPirateToSea(account, tokenIds[i]);
        } 
    }
// Solidity 0.8.10
/**
 * adds a single Pirate to the Sea
 * @param account the address of the staker
 * @param tokenId the ID of the Pirate to add to the Sea
 */
function _addPirateToSea(address account, uint256 tokenId) internal {
        uint8 rank = _rankForPirate(tokenId);
        totalRankStaked += rank; // Portion of earnings ranges from 8 to 5
        seaIndices[tokenId] = sea[rank].length; // Store the location of the pirate in the Sea
        sea[rank].push(Stake({
            owner: account,
            tokenId: uint16(tokenId),
            value: uint80(cacaoPerRank)
        })); // Add the pirate to the Sea
        emit TokenStaked(account, tokenId, false, cacaoPerRank);
    }
// Solidity 0.8.10
/**
 * realize $CACAO earnings and optionally unstake tokens from the Fleet / Sea
 * to unstake a Galleon it will require it has 2 days worth of $CACAO unclaimed
 * @param tokenIds the IDs of the tokens to claim earnings from
 * @param unstake whether or not to unstake ALL of the tokens listed in tokenIds
 */
function claimManyFromFleetAndSea(uint16[] calldata tokenIds, bool unstake) external 
        whenNotPaused 
        _updateEarnings 
        nonReentrant 
        onlyEOA
    {
        uint256 owed = 0;
        for (uint i = 0; i < tokenIds.length; i++) {
            if (nftContract.isGalleon(tokenIds[i])) {
                owed += _claimGalleonFromFleet(tokenIds[i], unstake);
            }
            else {
                owed += _claimPirateFromSea(tokenIds[i], unstake);
            }
        }
        cacao.updateInblockGuard();
        if (owed == 0) {
            return;
        }
        cacao.mint(_msgSender(), owed);
    }
// Solidity 0.8.10
/**
 * realize $CACAO earnings for a single Pirate and optionally unstake it
 * Pirates earn $CACAO proportional to their rank
 * @param tokenId the ID of the Pirate to claim earnings from
 * @param unstake whether or not to unstake the Pirate
 * @return owed - the amount of $CACAO earned
 */
function _claimPirateFromSea(uint256 tokenId, bool unstake) internal returns (uint256 owed) {
        require(nftContract.ownerOf(tokenId) == address(this), "Doesn't own token");
        uint8 rank = _rankForPirate(tokenId);
        Stake memory stake = sea[rank][seaIndices[tokenId]];
        require(stake.owner == _msgSender(), "Doesn't own token");
        owed = (rank) * (cacaoPerRank - stake.value); // Calculate portion of tokens based on Rank
        if (unstake) {
            totalRankStaked -= rank; // Remove rank from total staked
            Stake memory lastStake = sea[rank][sea[rank].length - 1];
            sea[rank][seaIndices[tokenId]] = lastStake; // Shuffle last Pirate to current position
            seaIndices[lastStake.tokenId] = seaIndices[tokenId];
            sea[rank].pop(); // Remove duplicate
            delete seaIndices[tokenId]; // Delete old mapping
            // Always remove last to guard against reentrance
            nftContract.safeTransferFrom(address(this), _msgSender(), tokenId, ""); // Send back Pirate
        } else {
            sea[rank][seaIndices[tokenId]] = Stake({
                owner: _msgSender(),
                tokenId: uint16(tokenId),
                value: uint80(cacaoPerRank)
            }); // reset stake
        }
        emit PirateClaimed(tokenId, unstake, owed);
    }
// Solidity 0.8.10
/** 
 * add $CACAO to claimable pot for the Sea
 * @param amount $CACAO to add to the pot
 */
function _payPirateTax(uint256 amount) internal {
        if (totalRankStaked == 0) { // if there's no staked pirates
            unaccountedRewards += amount; // keep track of $CACAO due to pirates
            return;
        }
        // makes sure to include any unaccounted $CACAO 
        cacaoPerRank += (amount + unaccountedRewards) / totalRankStaked;
        unaccountedRewards = 0;
    }
// Solidity 0.8.10
/**
 * chooses a random Pirate thief when a newly minted token is stolen
 * @param seed a random value to choose a Pirate from
 * @return the owner of the randomly selected Pirate thief
 */
function randomPirateOwner(uint256 seed) external view override returns (address) {
        if (totalRankStaked == 0) {
            return address(0x0);
        }
        uint256 bucket = (seed & 0xFFFFFFFF) % totalRankStaked; // choose a value from 0 to total rank staked
        uint256 cumulative;
        seed >>= 32;
        uint8 rank;
        // loop through each bucket of Pirates with the same rank score
        for (uint8 j = 0; j < _ranks.length; j++) {
            rank = _ranks[j];
            cumulative += sea[rank].length * rank;
            // if the value is not inside of that bucket, keep going
            if (bucket >= cumulative) continue;
            // get the address of a random Pirate with that rank score
            return sea[rank][seed % sea[rank].length].owner;
        }
        return address(0x0);
    }
// Solidity 0.7.5
/**
 * @notice Sets `amount` as the allowance of `spender` over the `owner` s tokens.
 * @param owner The address of the caller.
 * @param spender The address of the account which may transfer tokens
 * @param amount The number of tokens that are approved
 * @dev This internal function is equivalent to `approve`, and can be used to
 * e.g. set automatic allowances for certain subsystems, etc.
 * @dev Emits an Approval event.
 * @dev owner cannot be the zero address.
 * @dev spender cannot be the zero address.
 */
function _approve(
    address owner,
    address spender,
    uint96 amount
  ) internal virtual {
    require(
      owner != address(0),
      "Ctx::_approve: approve from the zero address"
    );
    require(
      spender != address(0),
      "Ctx::_approve: approve to the zero address"
    );

    allowances[owner][spender] = amount;
    emit Approval(owner, spender, amount);
  }
// Solidity 0.7.5
/**
 * @notice Atomically increases the allowance granted to `spender` by the caller.
 * @param spender address
 * @param addedValue uint256 raw
 * @dev This is an alternative to {approve} that can be used as a mitigation for
 * problems of Allowance Double-Spend Exploit.
 * @dev Emits Approval event indicating the updated allowance.
 * @dev spender cannot be the zero address.
 */
function increaseAllowance(address spender, uint256 addedValue)
    public
    virtual
    returns (bool)
  {
    uint96 amount;
    if (addedValue == uint256(-1)) {
      amount = uint96(-1);
    } else {
      amount = safe96(
        addedValue,
        "Ctx::increaseAllowance: amount exceeds 96 bits"
      );
    }
    _approve(
      msg.sender,
      spender,
      add96(
        allowances[msg.sender][spender],
        amount,
        "Ctx::increaseAllowance: transfer amount overflows"
      )
    );
    return true;
  }
// Solidity 0.7.6
/// @notice Update fees of the positions
/// @return baseLiquidity Fee of base position
/// @return limitLiquidity Fee of limit position
function zeroBurn() internal returns(uint128 baseLiquidity, uint128 limitLiquidity) {
      /// update fees for inclusion
      (baseLiquidity, , ) = _position(baseLower, baseUpper);
      if (baseLiquidity > 0) {
          pool.burn(baseLower, baseUpper, 0);
      }
      (limitLiquidity, , ) = _position(limitLower, limitUpper);
      if (limitLiquidity > 0) {
          pool.burn(limitLower, limitUpper, 0);
      }
    }
// Solidity 0.7.6
/// @notice Pull liquidity tokens from liquidity and receive the tokens
/// @param shares Number of liquidity tokens to pull from liquidity
/// @return base0 amount of token0 received from base position
/// @return base1 amount of token1 received from base position
/// @return limit0 amount of token0 received from limit position
/// @return limit1 amount of token1 received from limit position
function pullLiquidity(
      uint256 shares
    ) external onlyOwner returns(
        uint256 base0,
        uint256 base1,
        uint256 limit0,
        uint256 limit1
      ) {
        zeroBurn();
        (base0, base1) = _burnLiquidity(
            baseLower,
            baseUpper,
            _liquidityForShares(baseLower, baseUpper, shares),
            address(this),
            false
        );
        (limit0, limit1) = _burnLiquidity(
            limitLower,
            limitUpper,
            _liquidityForShares(limitLower, limitUpper, shares),
            address(this),
            false
        );
    }
// Solidity 0.7.6
/// @param shares Number of liquidity tokens to redeem as pool assets
/// @param to Address to which redeemed pool assets are sent
/// @param from Address from which liquidity tokens are sent
/// @return amount0 Amount of token0 redeemed by the submitted liquidity tokens
/// @return amount1 Amount of token1 redeemed by the submitted liquidity tokens
function withdraw(
        uint256 shares,
        address to,
        address from
    ) nonReentrant external override returns (uint256 amount0, uint256 amount1) {
        require(shares > 0, "shares");
        require(to != address(0), "to");

        /// update fees
        zeroBurn();

        /// Withdraw liquidity from Uniswap pool
        (uint256 base0, uint256 base1) = _burnLiquidity(
            baseLower,
            baseUpper,
            _liquidityForShares(baseLower, baseUpper, shares),
            to,
            false
        );
        (uint256 limit0, uint256 limit1) = _burnLiquidity(
            limitLower,
            limitUpper,
            _liquidityForShares(limitLower, limitUpper, shares),
            to,
            false
        );

        // Push tokens proportional to unused balances
        uint256 supply = totalSupply();
        uint256 unusedAmount0 = token0.balanceOf(address(this)).mul(shares).div(supply);
        uint256 unusedAmount1 = token1.balanceOf(address(this)).mul(shares).div(supply);
        if (unusedAmount0 > 0) token0.safeTransfer(to, unusedAmount0);
        if (unusedAmount1 > 0) token1.safeTransfer(to, unusedAmount1);

        amount0 = base0.add(limit0).add(unusedAmount0);
        amount1 = base1.add(limit1).add(unusedAmount1);

        require(
            from == msg.sender || IUniversalVault(from).owner() == msg.sender,
            "own"
        );
        _burn(from, shares);

        emit Withdraw(from, to, shares, amount0, amount1);
    }
// Solidity 0.7.6
/// @notice Compound pending fees
/// @return baseToken0Owed Pending fees of base token0
/// @return baseToken1Owed Pending fees of base token1
/// @return limitToken0Owed Pending fees of limit token0
/// @return limitToken1Owed Pending fees of limit token1
function compound() external onlyOwner returns (
      uint128 baseToken0Owed,
      uint128 baseToken1Owed,
      uint128 limitToken0Owed,
      uint128 limitToken1Owed
    ) {
      // update fees for compounding
      zeroBurn();
      (, baseToken0Owed,baseToken1Owed) = _position(baseLower, baseUpper);
      (, limitToken0Owed,limitToken1Owed) = _position(limitLower, limitUpper);
      
      // collect fees
      pool.collect(address(this), baseLower, baseLower, baseToken0Owed, baseToken1Owed);
      pool.collect(address(this), limitLower, limitUpper, limitToken0Owed, limitToken1Owed);
      
      uint128 baseLiquidity = _liquidityForAmounts(
        baseLower,
        baseUpper,
        token0.balanceOf(address(this)),
        token1.balanceOf(address(this))
      );
      _mintLiquidity(baseLower, baseUpper, baseLiquidity, address(this));

      uint128 limitLiquidity = _liquidityForAmounts(
        limitLower,
        limitUpper,
        token0.balanceOf(address(this)),
        token1.balanceOf(address(this))
      );
      _mintLiquidity(limitLower, limitUpper, limitLiquidity, address(this));
    }
// Solidity 0.7.6
/// @notice Add tokens to base liquidity
/// @param amount0 Amount of token0 to add
/// @param amount1 Amount of token1 to add
function addBaseLiquidity(uint256 amount0, uint256 amount1) external onlyOwner {
        uint128 baseLiquidity = _liquidityForAmounts(
            baseLower,
            baseUpper,
            amount0 == 0 && amount1 == 0 ? token0.balanceOf(address(this)) : amount0,
            amount0 == 0 && amount1 == 0 ? token1.balanceOf(address(this)) : amount1
        );
        _mintLiquidity(baseLower, baseUpper, baseLiquidity, address(this));
    }
// Solidity 0.7.6
/// @notice Adds the liquidity for the given position
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param liquidity The amount of liquidity to mint
/// @param payer Payer Data
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity
function _mintLiquidity(
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity,
        address payer
    ) internal returns (uint256 amount0, uint256 amount1) {
        if (liquidity > 0) {
            (amount0, amount1) = pool.mint(
                address(this),
                tickLower,
                tickUpper,
                liquidity,
                abi.encode(payer)
            );
        }
    }
// Solidity 0.7.6
/// @notice Burn liquidity from the sender and collect tokens owed for the liquidity
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param liquidity The amount of liquidity to burn
/// @param to The address which should receive the fees collected
/// @param collectAll If true, collect all tokens owed in the pool, else collect the owed tokens of the burn
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function _burnLiquidity(
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity,
        address to,
        bool collectAll
    ) internal returns (uint256 amount0, uint256 amount1) {
        if (liquidity > 0) {
            /// Burn liquidity
            (uint256 owed0, uint256 owed1) = pool.burn(tickLower, tickUpper, liquidity);

            // Collect amount owed
            uint128 collect0 = collectAll ? type(uint128).max : _uint128Safe(owed0);
            uint128 collect1 = collectAll ? type(uint128).max : _uint128Safe(owed1);
            if (collect0 > 0 || collect1 > 0) {
                (amount0, amount1) = pool.collect(to, tickLower, tickUpper, collect0, collect1);
            }
        }
    }
// Solidity 0.7.6
/// @notice Get the info of the given position
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @return liquidity The amount of liquidity of the position
/// @return tokensOwed0 Amount of token0 owed
/// @return tokensOwed1 Amount of token1 owed
function _position(int24 tickLower, int24 tickUpper)
        internal
        view
        returns (
            uint128 liquidity,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        )
    {
        bytes32 positionKey = keccak256(abi.encodePacked(address(this), tickLower, tickUpper));
        (liquidity, , , tokensOwed0, tokensOwed1) = pool.positions(positionKey);
    }
// Solidity 0.7.6
/// @notice Callback function of uniswapV3Pool mint
function uniswapV3MintCallback(
        uint256 amount0,
        uint256 amount1,
        bytes calldata data
    ) external override {
        require(msg.sender == address(pool));
        address payer = abi.decode(data, (address));

        if (payer == address(this)) {
            if (amount0 > 0) token0.safeTransfer(msg.sender, amount0);
            if (amount1 > 0) token1.safeTransfer(msg.sender, amount1);
        } else {
            if (amount0 > 0) token0.safeTransferFrom(payer, msg.sender, amount0);
            if (amount1 > 0) token1.safeTransferFrom(payer, msg.sender, amount1);
        }
    }
// Solidity 0.7.6
/// @notice Callback function of uniswapV3Pool swap
function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external override {
        require(msg.sender == address(pool));
        address payer = abi.decode(data, (address));

        if (amount0Delta > 0) {
            if (payer == address(this)) {
                token0.safeTransfer(msg.sender, uint256(amount0Delta));
            } else {
                token0.safeTransferFrom(payer, msg.sender, uint256(amount0Delta));
            }
        } else if (amount1Delta > 0) {
            if (payer == address(this)) {
                token1.safeTransfer(msg.sender, uint256(amount1Delta));
            } else {
                token1.safeTransferFrom(payer, msg.sender, uint256(amount1Delta));
            }
        }
    }
// Solidity 0.7.6
/// @return total0 Quantity of token0 in both positions and unused in the Hypervisor
/// @return total1 Quantity of token1 in both positions and unused in the Hypervisor
function getTotalAmounts() public view override returns (uint256 total0, uint256 total1) {
        (, uint256 base0, uint256 base1) = getBasePosition();
        (, uint256 limit0, uint256 limit1) = getLimitPosition();
        total0 = token0.balanceOf(address(this)).add(base0).add(limit0);
        total1 = token1.balanceOf(address(this)).add(base1).add(limit1);
    }
// Solidity 0.7.6
/// @return liquidity Amount of total liquidity in the base position
/// @return amount0 Estimated amount of token0 that could be collected by
/// burning the base position
/// @return amount1 Estimated amount of token1 that could be collected by
/// burning the base position
function getBasePosition()
        public
        view
        returns (
            uint128 liquidity,
            uint256 amount0,
            uint256 amount1
        )
    {
        (uint128 positionLiquidity, uint128 tokensOwed0, uint128 tokensOwed1) = _position(
            baseLower,
            baseUpper
        );
        (amount0, amount1) = _amountsForLiquidity(baseLower, baseUpper, positionLiquidity);
        amount0 = amount0.add(uint256(tokensOwed0));
        amount1 = amount1.add(uint256(tokensOwed1));
        liquidity = positionLiquidity;
    }
// Solidity 0.7.6
/// @notice Get the amounts of the given numbers of liquidity tokens
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param liquidity The amount of liquidity tokens
/// @return Amount of token0 and token1
function _amountsForLiquidity(
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity
    ) internal view returns (uint256, uint256) {
        (uint160 sqrtRatioX96, , , , , , ) = pool.slot0();
        return
            LiquidityAmounts.getAmountsForLiquidity(
                sqrtRatioX96,
                TickMath.getSqrtRatioAtTick(tickLower),
                TickMath.getSqrtRatioAtTick(tickUpper),
                liquidity
            );
    }
// Solidity 0.4.20
// @return true if the transaction can buy tokens
// check for valid time period, min amount and within cap
function validPurchase() internal constant returns (bool) {
    bool withinPeriod = startDate <= now && endDate >= now;
    bool nonZeroPurchase = msg.value != 0;
    bool minAmount = msg.value >= minimumParticipationAmount;
    bool withinCap = weiRaised.add(msg.value) <= cap;

    return withinPeriod && nonZeroPurchase && minAmount && !isFinalized && withinCap;
  }
// Solidity 0.5.16
// safety value to return ownership (anyone can invoke)
function returnOwnership(address forContract) public {
        bytes memory payload = abi.encodeWithSignature("nominateNewOwner(address)", owner);

        // solhint-disable avoid-low-level-calls
        (bool success, ) = forContract.call(payload);

        if (!success) {
            // then try legacy way
            bytes memory legacyPayload = abi.encodeWithSignature("nominateOwner(address)", owner);

            // solhint-disable avoid-low-level-calls
            (bool legacySuccess, ) = forContract.call(legacyPayload);

            require(legacySuccess, "Legacy nomination failed");
        }
    }
// Solidity 0.5.16
/**
 * @notice return the full vesting schedule entries vest for a given user.
 * @dev For DApps to display the vesting schedule for the
 * inflationary supply over 5 years. Solidity cant return variable length arrays
 * so this is returning pairs of data. Vesting Time at [0] and quantity at [1] and so on
 */
function checkAccountSchedule(address account) public view returns (uint[520] memory) {
        uint[520] memory _result;
        uint schedules = _numVestingEntries(account);
        for (uint i = 0; i < schedules; i++) {
            uint[2] memory pair = getVestingScheduleEntry(account, i);
            _result[i * 2] = pair[0];
            _result[i * 2 + 1] = pair[1];
        }
        return _result;
    }