lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.11
// This function is what other pusd pools will call to mint new PEGS (similar to the PUSD mint) 
function pool_mint(address m_address, uint256 m_amount) external onlyPools {        
        if(trackingVotes){
            uint32 srcRepNum = numCheckpoints[address(this)];
            uint96 srcRepOld = srcRepNum > 0 ? checkpoints[address(this)][srcRepNum - 1].votes : 0;
            uint96 srcRepNew = add96(srcRepOld, uint96(m_amount), "pool_mint new votes overflows");
            _writeCheckpoint(address(this), srcRepNum, srcRepOld, srcRepNew); // mint new votes
            trackVotes(address(this), m_address, uint96(m_amount));
        }

        super._mint(m_address, m_amount);
        emit PEGSMinted(address(this), m_address, m_amount);
    }
// Solidity 0.6.11
// This function is what other pusd pools will call to burn PEGS 
function pool_burn_from(address b_address, uint256 b_amount) external onlyPools {
        if(trackingVotes){
            trackVotes(b_address, address(this), uint96(b_amount));
            uint32 srcRepNum = numCheckpoints[address(this)];
            uint96 srcRepOld = srcRepNum > 0 ? checkpoints[address(this)][srcRepNum - 1].votes : 0;
            uint96 srcRepNew = sub96(srcRepOld, uint96(b_amount), "pool_burn_from new votes underflows");
            _writeCheckpoint(address(this), srcRepNum, srcRepOld, srcRepNew); // burn votes
        }

        super._burnFrom(b_address, b_amount);
        emit PEGSBurned(b_address, address(this), b_amount);
    }
// Solidity 0.8.2
/// @dev Checks if a given address currently has transferApproval for a particular fighter.
/// @param _claimant the address we are confirming brawler is approved for.
/// @param _tokenId fighter id, only valid when > 0
function _approvedFor(address _claimant, uint256 _tokenId)
        internal
        view
        returns (bool)
    {
        if (fighterIdToApproved[_tokenId] == _claimant) {
            return true;
        }

        bool _senderIsOperator = false;
        address _owner = fighterIdToOwner[_tokenId];
        address[] memory _validOperators = ownerToOperators[_owner];

        uint256 _operatorIndex;
        for (
            _operatorIndex = 0;
            _operatorIndex < _validOperators.length;
            _operatorIndex++
        ) {
            if (_validOperators[_operatorIndex] == _claimant) {
                _senderIsOperator = true;
                break;
            }
        }

        return _senderIsOperator;
    }
// Solidity 0.6.11
// From compound's _moveDelegates
// Keep track of votes. "Delegates" is a misnomer here
function trackVotes(address srcRep, address dstRep, uint96 amount) internal {
        if (srcRep != dstRep && amount > 0) {
            if (srcRep != address(0)) {
                uint32 srcRepNum = numCheckpoints[srcRep];
                uint96 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
                uint96 srcRepNew = sub96(srcRepOld, amount, "PEGS::_moveVotes: vote amount underflows");
                _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
            }

            if (dstRep != address(0)) {
                uint32 dstRepNum = numCheckpoints[dstRep];
                uint96 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
                uint96 dstRepNew = add96(dstRepOld, amount, "PEGS::_moveVotes: vote amount overflows");
                _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
            }
        }
    }
// Solidity 0.6.3
/**
 *  repays bond token, any user can call it
 */
function withdraw(uint256 tokenId) external {
        // check if token exists
        require(
            IBondToken(_bond).hasToken(tokenId),
            "bond token id does not exist");

        address user = _msgSender();

        // get token properties
        ( uint256 value, /* uint256 interest */, uint256 maturity ) = IBondToken(_bond)
            .getTokenInfo(tokenId);

        address owner = IERC721(_bond).ownerOf(tokenId);
        bool isOwner = owner == user;

        if (!isOwner) {
            require (
                IAllowList(_allowList).isAllowedAccount(user),
                "user is not allowed");
            require(
                block.timestamp > maturity + _claimPeriod,
                "claim period is not finished yet");
        }

        // check if enough money to repay
        require(IERC20(_eurxb).balanceOf(user) >= value,
            "not enough EURxb to withdraw");

        // burn EURxb
        IEURxb(_eurxb).burn(user, value);
        if (maturity > block.timestamp) {
            // only if maturity has not arrived yet
            IEURxb(_eurxb).removeMaturity(value, maturity);
        }

        if (!isOwner) {
            // if not owner, need to transfer ownership first
            IBondToken(_bond).safeTransferFrom(owner, user, tokenId);
        }

        // burn token
        IBondToken(_bond).burn(tokenId);
    }
// Solidity 0.6.12
/* Private allocation functions */
function _calculatePoolMax() private {
        uint256[] memory poolMax = new uint256[](combinedPoolAllocation.length);
        for (uint256 i = 0; i < combinedPoolAllocation.length; i++) {
            uint256 max = 0;
            for (uint256 j = 0; j < combinedPoolAllocation[i].length; j++) {
                max += combinedPoolAllocation[i][j];
            }
            poolMax[i] = max;
        }
        _poolMax = poolMax;
    }
// Solidity 0.6.12
/* PUBLIC ADMIN ONLY */
function withdraw() public payable override nonReentrant {
        require(
            hasRole(OWNER_ROLE, _msgSender()),
            "must have owner role to withdraw"
        );
        uint256 remainder = (address(this).balance);
        uint256 division = remainder.div(100);
        for (uint8 i = 0; i < splitAddresses.length; i++) {
            // if at last address send the remainder
            if (i == splitAddresses.length - 1) {
                Address.sendValue(payable(splitAddresses[i]), remainder);
            } else {
                uint256 alloc = division.mul(splitPercentage[i]);
                Address.sendValue(payable(splitAddresses[i]), alloc);
                remainder -= alloc;
            }
        }
    }
// Solidity 0.7.6
/**
 * @notice Cannot be used for already spawned positions
 * @notice Token using as main collateral must be whitelisted
 * @notice Depositing tokens must be pre-approved to vault address
 * @notice position actually considered as spawned only when usdpAmount > 0
 * @dev Spawns new positions
 * @param asset The address of token using as main collateral
 * @param mainAmount The amount of main collateral to deposit
 * @param usdpAmount The amount of USDP token to borrow
 **/
function spawn(address asset, uint mainAmount, uint usdpAmount) public nonReentrant {
        require(usdpAmount != 0, "Unit Protocol: ZERO_BORROWING");

        // check whether the position is spawned
        require(vault.getTotalDebt(asset, msg.sender) == 0, "Unit Protocol: SPAWNED_POSITION");

        // oracle availability check
        require(vault.vaultParameters().isOracleTypeEnabled(ORACLE_TYPE, asset), "Unit Protocol: WRONG_ORACLE_TYPE");

        // USDP minting triggers the spawn of a position
        vault.spawn(asset, msg.sender, ORACLE_TYPE);

        _depositAndBorrow(asset, msg.sender, mainAmount, usdpAmount);

        // fire an event
        emit Join(asset, msg.sender, mainAmount, usdpAmount);
    }
// Solidity 0.7.6
/**
 * @notice Cannot be used for already spawned positions
 * @notice WETH must be whitelisted as collateral
 * @notice position actually considered as spawned only when usdpAmount > 0
 * @dev Spawns new positions using ETH
 * @param usdpAmount The amount of USDP token to borrow
 **/
function spawn_Eth(uint usdpAmount) public payable nonReentrant {
        require(usdpAmount != 0, "Unit Protocol: ZERO_BORROWING");

        // check whether the position is spawned
        require(vault.getTotalDebt(vault.weth(), msg.sender) == 0, "Unit Protocol: SPAWNED_POSITION");

        // oracle availability check
        require(vault.vaultParameters().isOracleTypeEnabled(ORACLE_TYPE, vault.weth()), "Unit Protocol: WRONG_ORACLE_TYPE");

        // USDP minting triggers the spawn of a position
        vault.spawn(vault.weth(), msg.sender, ORACLE_TYPE);

        _depositAndBorrow_Eth(msg.sender, usdpAmount);

        // fire an event
        emit Join(vault.weth(), msg.sender, msg.value, usdpAmount);
    }
// Solidity 0.7.6
/**
 * @notice Position should be spawned (USDP borrowed from position) to call this method
 * @notice Depositing tokens must be pre-approved to vault address
 * @notice Token using as main collateral must be whitelisted
 * @dev Deposits collaterals and borrows USDP to spawned positions simultaneously
 * @param asset The address of token using as main collateral
 * @param mainAmount The amount of main collateral to deposit
 * @param usdpAmount The amount of USDP token to borrow
 **/
function depositAndBorrow(
        address asset,
        uint mainAmount,
        uint usdpAmount
    )
    public
    spawned(asset, msg.sender)
    nonReentrant
    {
        require(usdpAmount != 0, "Unit Protocol: ZERO_BORROWING");

        _depositAndBorrow(asset, msg.sender, mainAmount, usdpAmount);

        // fire an event
        emit Join(asset, msg.sender, mainAmount, usdpAmount);
    }
// Solidity 0.7.6
/**
 * @notice Tx sender must have a sufficient USDP balance to pay the debt
 * @dev Withdraws collateral and repays specified amount of debt simultaneously
 * @param asset The address of token using as main collateral
 * @param mainAmount The amount of main collateral token to withdraw
 * @param usdpAmount The amount of USDP token to repay
 **/
function withdrawAndRepay(
        address asset,
        uint mainAmount,
        uint usdpAmount
    )
    public
    spawned(asset, msg.sender)
    nonReentrant
    {
        // check usefulness of tx
        require(mainAmount != 0, "Unit Protocol: USELESS_TX");

        uint debt = vault.debts(asset, msg.sender);
        require(debt != 0 && usdpAmount != debt, "Unit Protocol: USE_REPAY_ALL_INSTEAD");

        if (mainAmount != 0) {
            // withdraw main collateral to the user address
            vault.withdrawMain(asset, msg.sender, mainAmount);
        }

        if (usdpAmount != 0) {
            uint fee = vault.calculateFee(asset, msg.sender, usdpAmount);
            vault.chargeFee(vault.usdp(), msg.sender, fee);
            vault.repay(asset, msg.sender, usdpAmount);
        }

        vault.update(asset, msg.sender);

        _ensurePositionCollateralization(asset, msg.sender);

        // fire an event
        emit Exit(asset, msg.sender, mainAmount, usdpAmount);
    }
// Solidity 0.7.6
/**
 * @notice Tx sender must have a sufficient USDP balance to pay the debt
 * @dev Withdraws collateral and repays specified amount of debt simultaneously converting WETH to ETH
 * @param ethAmount The amount of ETH to withdraw
 * @param usdpAmount The amount of USDP token to repay
 **/
function withdrawAndRepay_Eth(
        uint ethAmount,
        uint usdpAmount
    )
    public
    spawned(vault.weth(), msg.sender)
    nonReentrant
    {
        // check usefulness of tx
        require(ethAmount != 0, "Unit Protocol: USELESS_TX");

        uint debt = vault.debts(vault.weth(), msg.sender);
        require(debt != 0 && usdpAmount != debt, "Unit Protocol: USE_REPAY_ALL_INSTEAD");

        if (ethAmount != 0) {
            // withdraw main collateral to the user address
            vault.withdrawEth(msg.sender, ethAmount);
        }

        if (usdpAmount != 0) {
            uint fee = vault.calculateFee(vault.weth(), msg.sender, usdpAmount);
            vault.chargeFee(vault.usdp(), msg.sender, fee);
            vault.repay(vault.weth(), msg.sender, usdpAmount);
        }

        vault.update(vault.weth(), msg.sender);

        _ensurePositionCollateralization_Eth(msg.sender);

        // fire an event
        emit Exit(vault.weth(), msg.sender, ethAmount, usdpAmount);
    }
// Solidity 0.7.6
// ensures that borrowed value is in desired range
function _ensureCollateralization(
        address asset,
        address user,
        uint mainUsdValue_q112
    )
    internal
    view
    {
        // USD limit of the position
        uint usdLimit = mainUsdValue_q112 * vaultManagerParameters.initialCollateralRatio(asset) / Q112 / 100;

        // revert if collateralization is not enough
        require(vault.getTotalDebt(asset, user) <= usdLimit, "Unit Protocol: UNDERCOLLATERALIZED");
    }
// Solidity 0.8.7
/// WALK THE PLANK ///
function walkPlank() external whenNotPaused nonReentrant {
        require(tx.origin == msg.sender, "Only EOA");
        require(_pendingPlankCommitId[msg.sender] == 0, "Already have pending mints");
        uint16 totalPirats = uint16(potm.getTotalPirats());
        uint16 totalPending = pendingMintAmt + pendingPlankAmt;
        uint256 maxTokens = potm.maxTokens();
        require(totalPirats + totalPending + 1 <= maxTokens, "All tokens minted");
        uint256 totalBootyCost = 0;
        for (uint i = 1; i <= 1; i++) {
            totalBootyCost += plankCost(totalPirats + totalPending + i);
            }
        if (totalBootyCost > 0) {
            booty.burnExternal(msg.sender, totalBootyCost);
        }
        _plankCommitId += 1;
        uint16 commitId = _plankCommitId;
        _plankCommits[msg.sender][commitId] = PlankCommit(1);       
        _pendingPlankCommitId[msg.sender] = commitId;
        pendingPlankAmt += 1;
        uint256 randomNumber = _rand(commitId);
        commitIdToRandomNumber[commitId] = randomNumber;        
        commitTimeStamp[msg.sender] = block.timestamp;
        emit PlankCommitted(msg.sender, 1);
    }
// Solidity 0.4.18
/// For creating Rich Token
function _createRich(string _name, address _owner, uint256 _price) private {
    Rich memory _richtoken = Rich({
      name: _name
    });
    uint256 newRichId = richtokens.push(_richtoken) - 1;

    // It's probably never going to happen, 4 billion tokens are A LOT, but
    // let's just be 100% sure we never let this happen.
    require(newRichId == uint256(uint32(newRichId)));

    Birth(newRichId, _name, _owner);

    richtokenIndexToPrice[newRichId] = _price;

    // This will assign ownership, and also emit the Transfer event as
    // per ERC721 draft
    _transfer(address(0), _owner, newRichId);
  }
// Solidity 0.7.6
/**
 * @dev Updates parameters of the position to the current ones
 * @param asset The address of the main collateral token
 * @param user The owner of a position
 **/
function update(address asset, address user) public hasVaultAccess notLiquidating(asset, user) {

        // calculate fee using stored stability fee
        uint debtWithFee = getTotalDebt(asset, user);
        tokenDebts[asset] = tokenDebts[asset].sub(debts[asset][user]).add(debtWithFee);
        debts[asset][user] = debtWithFee;

        stabilityFee[asset][user] = vaultParameters.stabilityFee(asset);
        liquidationFee[asset][user] = vaultParameters.liquidationFee(asset);
        lastUpdate[asset][user] = block.timestamp;
    }
// Solidity 0.7.6
/**
 * @dev Increases position's debt and mints USDP token
 * @param asset The address of the main collateral token
 * @param user The address of a position's owner
 * @param amount The amount of USDP to borrow
 **/
function borrow(
        address asset,
        address user,
        uint amount
    )
    external
    hasVaultAccess
    notLiquidating(asset, user)
    returns(uint)
    {
        require(vaultParameters.isOracleTypeEnabled(oracleType[asset][user], asset), "Unit Protocol: WRONG_ORACLE_TYPE");
        update(asset, user);
        debts[asset][user] = debts[asset][user].add(amount);
        tokenDebts[asset] = tokenDebts[asset].add(amount);

        // check USDP limit for token
        require(tokenDebts[asset] <= vaultParameters.tokenDebtLimit(asset), "Unit Protocol: ASSET_DEBT_LIMIT");

        USDP(usdp).mint(user, amount);

        return debts[asset][user];
    }
// Solidity 0.7.6
/**
 * @dev Deletes position and transfers collateral to liquidation system
 * @param asset The address of the main collateral token
 * @param positionOwner The address of a position's owner
 * @param initialPrice The starting price of collateral in USDP
 **/
function triggerLiquidation(
        address asset,
        address positionOwner,
        uint initialPrice
    )
    external
    hasVaultAccess
    notLiquidating(asset, positionOwner)
    {
        // reverts if oracle type is disabled
        require(vaultParameters.isOracleTypeEnabled(oracleType[asset][positionOwner], asset), "Unit Protocol: WRONG_ORACLE_TYPE");

        // fix the debt
        debts[asset][positionOwner] = getTotalDebt(asset, positionOwner);

        liquidationBlock[asset][positionOwner] = block.number;
        liquidationPrice[asset][positionOwner] = initialPrice;
    }
// Solidity 0.6.12
// Functions
// Transaction overview:
// 1. User approves transfer of token to AtomicSwap contract (triggered by the frontend)
// 2. User calls AtomicSwap.swapExactTokensAndMint() (triggered by the frontend)
//    2.1 AtomicSwap transfers token from user to itself (internal tx)
//    2.2 AtomicSwap approves IUniswapV2Router02 (internal tx)
//    2.3 AtomicSwap calls IUniswapV2Router02.swapExactTokensForTokens() to exchange token for collateral (internal tx)
//    2.4 AtomicSwap approves SynthereumPool (internal tx)
//    2.5 AtomicSwap calls SynthereumPool.mint() to mint synth with collateral (internal tx)
function swapExactTokensAndMint(
    uint256 tokenAmountIn,
    uint256 collateralAmountOut,
    address[] calldata tokenSwapPath,
    ISynthereumPoolOnChainPriceFeed synthereumPool,
    ISynthereumPoolOnChainPriceFeed.MintParams memory mintParams
  )
    public
    returns (
      uint256 collateralOut,
      IERC20 synthToken,
      uint256 syntheticTokensMinted
    )
  {
    IERC20 collateralInstance = checkPoolRegistration(synthereumPool);
    uint256 numberOfSwapTokens = tokenSwapPath.length - 1;
    require(
      address(collateralInstance) == tokenSwapPath[numberOfSwapTokens],
      'Wrong collateral instance'
    );

    synthToken = synthereumPool.syntheticToken();
    IERC20 inputTokenInstance = IERC20(tokenSwapPath[0]);

    inputTokenInstance.safeTransferFrom(
      msg.sender,
      address(this),
      tokenAmountIn
    );

    inputTokenInstance.safeApprove(address(uniswapRouter), tokenAmountIn);

    collateralOut = uniswapRouter.swapExactTokensForTokens(
      tokenAmountIn,
      collateralAmountOut,
      tokenSwapPath,
      address(this),
      mintParams.expiration
    )[numberOfSwapTokens];

    collateralInstance.safeApprove(address(synthereumPool), collateralOut);

    mintParams.collateralAmount = collateralOut;
    (syntheticTokensMinted, ) = synthereumPool.mint(mintParams);

    emit Swap(
      address(inputTokenInstance),
      tokenAmountIn,
      address(synthToken),
      syntheticTokensMinted
    );
  }
// Solidity 0.6.12
// Transaction overview:
// 1. User approves transfer of token to AtomicSwap contract (triggered by the frontend)
// 2. User calls AtomicSwap.swapTokensForExactAndMint() (triggered by the frontend)
//    2.1 AtomicSwap transfers token from user to itself (internal tx)
//    2.2 AtomicSwap approves IUniswapV2Router02 (internal tx)
//    2.3 AtomicSwap checks the return amounts of the swapTokensForExactTokens() function and saves the leftover of the inputTokenAmount in a variable
//    2.4 AtomicSwap calls IUniswapV2Router02.swapTokensForExactTokens() to exchange token for collateral (internal tx)
//    2.5 AtomicSwap approves SynthereumPool (internal tx)
//    2.6 AtomicSwap calls SynthereumPool.mint() to mint synth with collateral (internal tx)
//    2.7 AtomicSwap transfers the remaining input tokens to the user
function swapTokensForExactAndMint(
    uint256 tokenAmountIn,
    uint256 collateralAmountOut,
    address[] calldata tokenSwapPath,
    ISynthereumPoolOnChainPriceFeed synthereumPool,
    ISynthereumPoolOnChainPriceFeed.MintParams memory mintParams
  )
    public
    returns (
      uint256 collateralOut,
      IERC20 synthToken,
      uint256 syntheticTokensMinted
    )
  {
    IERC20 collateralInstance = checkPoolRegistration(synthereumPool);
    uint256 numberOfSwapTokens = tokenSwapPath.length - 1;
    require(
      address(collateralInstance) == tokenSwapPath[numberOfSwapTokens],
      'Wrong collateral instance'
    );

    synthToken = synthereumPool.syntheticToken();
    IERC20 inputTokenInstance = IERC20(tokenSwapPath[0]);

    inputTokenInstance.safeTransferFrom(
      msg.sender,
      address(this),
      tokenAmountIn
    );

    uint256[2] memory amounts =
      _getNeededAmountAndLeftover(
        collateralAmountOut,
        tokenSwapPath,
        tokenAmountIn
      );

    inputTokenInstance.safeApprove(address(uniswapRouter), amounts[0]);

    collateralOut = uniswapRouter.swapTokensForExactTokens(
      collateralAmountOut,
      amounts[0],
      tokenSwapPath,
      address(this),
      mintParams.expiration
    )[numberOfSwapTokens];

    collateralInstance.safeApprove(address(synthereumPool), collateralOut);

    mintParams.collateralAmount = collateralOut;
    (syntheticTokensMinted, ) = synthereumPool.mint(mintParams);

    if (amounts[1] != 0) {
      inputTokenInstance.safeTransfer(mintParams.recipient, amounts[1]);
    }

    emit Swap(
      address(inputTokenInstance),
      tokenAmountIn,
      address(synthToken),
      syntheticTokensMinted
    );
  }
// Solidity 0.6.12
// Transaction overview:
// 1. User approves transfer of synth to `AtomicSwap` contract (triggered by the frontend)
// 2. User calls `AtomicSwap.redeemAndSwapExactTokens()` (triggered by the frontend)
//   2.1 `AtomicSwaps` transfers synth from user to itself (internal tx)
//   2.2 `AtomicSwaps` approves transfer of synth from itself to pool (internal tx)
//   2.3 `AtomicSwap` calls `pool.redeem()` to redeem synth for collateral (internal tx)
//   2.4 `AtomicSwap` approves transfer of collateral to `IUniswapV2Router02` (internal tx)
//   2.7 `AtomicSwap` calls `IUniswapV2Router02.swapExactTokensForTokens` to swap collateral for token (internal tx)
function redeemAndSwapExactTokens(
    uint256 amountTokenOut,
    address[] calldata tokenSwapPath,
    ISynthereumPoolOnChainPriceFeed synthereumPool,
    ISynthereumPoolOnChainPriceFeed.RedeemParams memory redeemParams,
    address recipient
  )
    public
    returns (
      uint256 collateralRedeemed,
      IERC20 outputToken,
      uint256 outputTokenAmount
    )
  {
    IERC20 collateralInstance = checkPoolRegistration(synthereumPool);
    require(
      address(collateralInstance) == tokenSwapPath[0],
      'Wrong collateral instance'
    );

    IERC20 synthToken = synthereumPool.syntheticToken();
    outputToken = IERC20(tokenSwapPath[tokenSwapPath.length - 1]);

    uint256 numTokens = redeemParams.numTokens;
    synthToken.safeTransferFrom(msg.sender, address(this), numTokens);
    synthToken.safeApprove(address(synthereumPool), numTokens);

    redeemParams.recipient = address(this);
    (collateralRedeemed, ) = synthereumPool.redeem(redeemParams);

    collateralInstance.safeApprove(address(uniswapRouter), collateralRedeemed);

    outputTokenAmount = uniswapRouter.swapExactTokensForTokens(
      collateralRedeemed,
      amountTokenOut,
      tokenSwapPath,
      recipient,
      redeemParams.expiration
    )[tokenSwapPath.length - 1];

    emit Swap(
      address(synthToken),
      numTokens,
      address(outputToken),
      outputTokenAmount
    );
  }