lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.7.5
/**
 @notice allow approved address to deposit an asset for OHM
 @param _amount uint
 @param _token address
 @param _profit uint
 @return send_ uint
 */
function deposit( uint _amount, address _token, uint _profit ) external returns ( uint send_ ) {
        require( isReserveToken[ _token ] || isLiquidityToken[ _token ], "Not accepted" );
        IERC20( _token ).safeTransferFrom( msg.sender, address(this), _amount );

        if ( isReserveToken[ _token ] ) {
            require( isReserveDepositor[ msg.sender ], "Not approved" );
        } else {
            require( isLiquidityDepositor[ msg.sender ], "Not approved" );
        }

        uint value = valueOf(_token, _amount);
        // mint OHM needed and store amount of rewards for distribution
        send_ = value.sub( _profit );
        IERC20Mintable( OHM ).mint( msg.sender, send_ );

        totalReserves = totalReserves.add( value );
        emit ReservesUpdated( totalReserves );

        emit Deposit( _token, _amount, value );
    }
// Solidity 0.7.5
/**
 @notice allow approved address to burn OHM for reserves
 @param _amount uint
 @param _token address
 */
function withdraw( uint _amount, address _token ) external {
        require( isReserveToken[ _token ], "Not accepted" ); // Only reserves can be used for redemptions
        require( isReserveSpender[ msg.sender ] == true, "Not approved" );

        uint value = valueOf( _token, _amount );
        IOHMERC20( OHM ).burnFrom( msg.sender, value );

        totalReserves = totalReserves.sub( value );
        emit ReservesUpdated( totalReserves );

        IERC20( _token ).safeTransfer( msg.sender, _amount );

        emit Withdrawal( _token, _amount, value );
    }
// Solidity 0.7.5
/**
 @notice allow approved address to borrow reserves
 @param _amount uint
 @param _token address
 */
function incurDebt( uint _amount, address _token ) external {
        require( isDebtor[ msg.sender ], "Not approved" );
        require( isReserveToken[ _token ], "Not accepted" );

        uint value = valueOf( _token, _amount );

        uint maximumDebt = IERC20( sOHM ).balanceOf( msg.sender ); // Can only borrow against sOHM held
        uint availableDebt = maximumDebt.sub( debtorBalance[ msg.sender ] );
        require( value <= availableDebt, "Exceeds debt limit" );

        debtorBalance[ msg.sender ] = debtorBalance[ msg.sender ].add( value );
        totalDebt = totalDebt.add( value );

        totalReserves = totalReserves.sub( value );
        emit ReservesUpdated( totalReserves );

        IERC20( _token ).transfer( msg.sender, _amount );

        emit CreateDebt( msg.sender, _token, _amount, value );
    }
// Solidity 0.7.5
/**
 @notice allow approved address to repay borrowed reserves with OHM
 @param _amount uint
 */
function repayDebtWithOHM( uint _amount ) external {
        require( isDebtor[ msg.sender ], "Not approved" );

        IOHMERC20( OHM ).burnFrom( msg.sender, _amount );

        debtorBalance[ msg.sender ] = debtorBalance[ msg.sender ].sub( _amount );
        totalDebt = totalDebt.sub( _amount );

        emit RepayDebt( msg.sender, OHM, _amount, _amount );
    }
// Solidity 0.7.5
/**
 @notice allow approved address to withdraw assets
 @param _token address
 @param _amount uint
 */
function manage( address _token, uint _amount ) external {
        if( isLiquidityToken[ _token ] ) {
            require( isLiquidityManager[ msg.sender ], "Not approved" );
        } else {
            require( isReserveManager[ msg.sender ], "Not approved" );
        }

        uint value = valueOf(_token, _amount);
        require( value <= excessReserves(), "Insufficient reserves" );

        totalReserves = totalReserves.sub( value );
        emit ReservesUpdated( totalReserves );

        IERC20( _token ).safeTransfer( msg.sender, _amount );

        emit ReservesManaged( _token, _amount );
    }
// Solidity 0.7.5
/**
 @notice takes inventory of all tracked assets
 @notice always consolidate to recognized reserves before audit
 */
function auditReserves() external onlyManager() {
        uint reserves;
        for( uint i = 0; i < reserveTokens.length; i++ ) {
            reserves = reserves.add (
                valueOf( reserveTokens[ i ], IERC20( reserveTokens[ i ] ).balanceOf( address(this) ) )
            );
        }
        for( uint i = 0; i < liquidityTokens.length; i++ ) {
            reserves = reserves.add (
                valueOf( liquidityTokens[ i ], IERC20( liquidityTokens[ i ] ).balanceOf( address(this) ) )
            );
        }
        totalReserves = reserves;
        emit ReservesUpdated( reserves );
        emit ReservesAudited( reserves );
    }
// Solidity 0.7.5
/**
 @notice returns OHM valuation of asset
 @param _token address
 @param _amount uint
 @return value_ uint
 */
function valueOf( address _token, uint _amount ) public view returns ( uint value_ ) {
        if ( isReserveToken[ _token ] ) {
            // convert amount to match OHM decimals
            value_ = _amount.mul( 10 ** IERC20( OHM ).decimals() ).div( 10 ** IERC20( _token ).decimals() );
        } else if ( isLiquidityToken[ _token ] ) {
            value_ = IBondCalculator( bondCalculator[ _token ] ).valuation( _token, _amount );
        }
    }
// Solidity 0.7.5
/**
 @notice checks requirements and returns altered structs
 @param queue_ mapping( address => uint )
 @param status_ mapping( address => bool )
 @param _address address
 @return bool
 */
function requirements(
        mapping( address => uint ) storage queue_,
        mapping( address => bool ) storage status_,
        address _address
    ) internal view returns ( bool ) {
        if ( !status_[ _address ] ) {
            require( queue_[ _address ] != 0, "Must queue" );
            require( queue_[ _address ] <= block.number, "Queue not expired" );
            return true;
        } return false;
    }
// Solidity 0.7.5
/**
 @notice checks array to ensure against duplicate
 @param _list address[]
 @param _token address
 @return bool
 */
function listContains( address[] storage _list, address _token ) internal view returns ( bool ) {
        for( uint i = 0; i < _list.length; i++ ) {
            if( _list[ i ] == _token ) {
                return true;
            }
        }
        return false;
    }
// Solidity 0.6.12
/**
 	* @dev Set circuitBreak to freeze/unfreeze all handlers
 	* @param _emergency The boolean status of circuitBreaker (on/off)
 	* @return true (TODO: validate results)
 	*/
function setCircuitBreaker(bool _emergency) onlyBreaker external override returns (bool)
	{
		for (uint256 handlerID = 0; handlerID < tokenHandlerLength; handlerID++)
		{
			proxyContractInterface tokenHandler = proxyContractInterface(dataStorageInstance.getTokenHandlerAddr(handlerID));

			// use delegate call via handler proxy
			// for token handlers
			bytes memory callData = abi.encodeWithSelector(
				marketHandlerInterface
				.setCircuitBreaker.selector,
				_emergency
			);

			tokenHandler.handlerProxy(callData);
			tokenHandler.siProxy(callData);
		}

		liquidationManagerInterface liquidationManager = liquidationManagerInterface(dataStorageInstance.getLiquidationManagerAddr());
		liquidationManager.setCircuitBreaker(_emergency);
		emergency = _emergency;
		return true;
	}
// Solidity 0.6.12
/**
 	* @dev Reward the user (msg.sender) with the reward token after calculating interest.
 	* @return true (TODO: validate results)
 	*/
function interestUpdateReward() external override returns (bool)
	{
		uint256 thisBlock = block.number;
		uint256 interestRewardUpdated = dataStorageInstance.getInterestRewardUpdated();
		uint256 delta = thisBlock - interestRewardUpdated;
		if (delta == 0)
		{
			return false;
		}

		dataStorageInstance.setInterestRewardUpdated(thisBlock);
		for (uint256 handlerID; handlerID < tokenHandlerLength; handlerID++)
		{
			proxyContractInterface tokenHandler = proxyContractInterface(dataStorageInstance.getTokenHandlerAddr(handlerID));
			bytes memory data;
			(, data) = tokenHandler.handlerProxy(
				abi.encodeWithSelector(
					marketHandlerInterface
					.checkFirstAction.selector
				)
			);
		}

		/* transfer reward tokens */
		return _rewardTransfer(msg.sender, delta.mul(dataStorageInstance.getInterestUpdateRewardPerblock()));
	}
// Solidity 0.6.12
/* TODO: comment */
function _claimHandlerRewardAmount(uint256 handlerID, address payable userAddr) internal returns (uint256) {
		bytes memory data;

		proxyContractInterface tokenHandler = proxyContractInterface(dataStorageInstance.getTokenHandlerAddr(handlerID));
		tokenHandler.siProxy(
			abi.encodeWithSelector(
				SIInterface
				.updateRewardLane.selector,
				userAddr
			)
		);

		/* Claim reward for a token handler */
		(, data) = tokenHandler.siProxy(
			abi.encodeWithSelector(
				SIInterface.claimRewardAmountUser.selector,
				userAddr
			)
		);
		return abi.decode(data, (uint256));
	}
// Solidity 0.6.12
/**
 	* @dev Transfer reward tokens to a user
 	* @param userAddr The address of recipient
 	* @param _amount The amount of the reward token
 	* @return true (TODO: validate results)
 	*/
function _rewardTransfer(address payable userAddr, uint256 _amount) internal returns (bool)
	{
		IERC20 _rewardERC20 = rewardErc20Instance;

		if(address(_rewardERC20) != address(0x0)) {
			uint256 beforeBalance = _rewardERC20.balanceOf(userAddr);
			_rewardERC20.transfer(userAddr, _amount);
			require(_amount == _rewardERC20.balanceOf(userAddr).sub(beforeBalance), REWARD_TRANSFER);
			return true;
		}
	}
// Solidity 0.6.12
/**
 	* @dev Epilogue of _determineRewardParams for code-size savings
 	* @param _dataStorage interface of Manager Data Storage
 	* @param userAddr User Address for Reward token transfer
 	* @param _delta The inactive period (delta) since the last action happens
 	* @param _globalRewardPerBlock Reward per block
 	* @param _globalRewardDecrement Rewards decrement for a block
 	* @param _globalRewardTotalAmount Total amount of rewards
 	* @return true (TODO: validate results)
 	*/
function _epilogueOfDetermineRewardParams(
		managerDataStorageInterfaceForManager _dataStorage,
		address payable userAddr,
		uint256 _delta,
		uint256 _globalRewardPerBlock,
		uint256 _globalRewardDecrement,
		uint256 _globalRewardTotalAmount
	) internal returns (bool) {
    // Set the reward model parameters
    _dataStorage.setGlobalRewardPerBlock(_globalRewardPerBlock);
		_dataStorage.setGlobalRewardDecrement(_globalRewardDecrement);
		_dataStorage.setGlobalRewardTotalAmount(_globalRewardTotalAmount);

		uint256 rewardAmount = _delta.mul(_dataStorage.getRewardParamUpdateRewardPerBlock());
		/* To incentivze the update operation, the operator get paid with the
		reward token */
		_rewardTransfer(userAddr, rewardAmount);
		return true;
	}
// Solidity 0.6.12
/**
 	* @dev Update rewards paramters of token handlers.
 	* @param userAddr The address of operator
 	* @return true (TODO: validate results)
 	*/
function _calcRewardParams(address payable userAddr) internal returns (bool)
	{
		uint256 handlerLength = tokenHandlerLength;
		bytes memory data;
		uint256[] memory handlerAlphaRateBaseAsset = new uint256[](handlerLength);
		uint256[] memory chainAlphaRateBaseAsset;
		uint256 handlerID;
		uint256 alphaRateBaseGlobalAssetSum;
		for (handlerID; handlerID < handlerLength; handlerID++)
		{
			handlerAlphaRateBaseAsset[handlerID] = _getAlphaBaseAsset(handlerID);
			alphaRateBaseGlobalAssetSum = alphaRateBaseGlobalAssetSum.add(handlerAlphaRateBaseAsset[handlerID]);
		}

		chainAlphaRateBaseAsset = observer.getAlphaBaseAsset();
		handlerID = 0;
		for (;handlerID < chainAlphaRateBaseAsset.length; handlerID++) {
			alphaRateBaseGlobalAssetSum = alphaRateBaseGlobalAssetSum.add(chainAlphaRateBaseAsset[handlerID]);
		}

		handlerID = 0;
		uint256 globalRewardPerBlocks = dataStorageInstance.getGlobalRewardPerBlock();

		for (handlerID; handlerID < handlerLength; handlerID++)
		{
			proxyContractInterface tokenHandler = proxyContractInterface(dataStorageInstance.getTokenHandlerAddr(handlerID));
			(, data) = tokenHandler.siProxy(
				abi.encodeWithSelector(
					SIInterface
					.updateRewardLane.selector,
					userAddr
				)
			);

			/* Update reward parameter for the token handler */
			uint256 rewardPerBlocks = globalRewardPerBlocks
								.unifiedMul(
								handlerAlphaRateBaseAsset[handlerID]
								.unifiedDiv(alphaRateBaseGlobalAssetSum)
								);
			data = abi.encodeWithSelector(
				SIInterface.updateRewardPerBlockLogic.selector,
				rewardPerBlocks
			);
			(, data) = tokenHandler.siProxy(data);

			emit HandlerRewardUpdate(handlerID, handlerAlphaRateBaseAsset[handlerID], rewardPerBlocks);
		}

		handlerID = 0;
		for (;handlerID < chainAlphaRateBaseAsset.length; handlerID++) {
			uint256 rewardPerBlocks = chainAlphaRateBaseAsset[handlerID]
										.unifiedDiv(alphaRateBaseGlobalAssetSum)
										.unifiedMul(globalRewardPerBlocks);

			observer.setChainGlobalRewardPerblock(
				handlerID,
				rewardPerBlocks
			);
			emit ChainRewardUpdate(handlerID, chainAlphaRateBaseAsset[handlerID], rewardPerBlocks);
		}

		return true;
	}
// Solidity 0.6.12
/**
 	* @dev Calculate the alpha-score for the handler (in USD price)
 	* @param _handlerID The handler ID
 	* @return The alpha-score of the handler
 	*/
function _getAlphaBaseAsset(uint256 _handlerID) internal view returns (uint256)
	{
		bytes memory data;
		proxyContractInterface tokenHandler = proxyContractInterface(dataStorageInstance.getTokenHandlerAddr(_handlerID));

    // TODO merge call
		(, data) = tokenHandler.handlerViewProxy(
			abi.encodeWithSelector(
				marketHandlerInterface
				.getDepositTotalAmount.selector
			)
		);
		uint256 _depositAmount = abi.decode(data, (uint256));

		(, data) = tokenHandler.handlerViewProxy(
			abi.encodeWithSelector(
				marketHandlerInterface
				.getBorrowTotalAmount.selector
			)
		);
		uint256 _borrowAmount = abi.decode(data, (uint256));

		return _calcAlphaBaseAmount(
              dataStorageInstance.getAlphaRate(),
              _depositAmount,
              _borrowAmount
            )
            .unifiedMul(_getTokenHandlerPrice(_handlerID));
	}
// Solidity 0.6.12
/// @dev Calculate the wallet address for the given owner and Switcheo TradeHub address
/// @param _ownerAddress the Ethereum address which the user has control over, i.e. can sign msgs with
/// @param _swthAddress the hex value of the user's Switcheo TradeHub address
/// @param _bytecodeHash the hash of the wallet contract's bytecode
/// @return the wallet address
function getWalletAddress(
        address _ownerAddress,
        bytes calldata _swthAddress,
        bytes32 _bytecodeHash
    )
        external
        view
        returns (address)
    {
        bytes32 salt = _getSalt(
            _ownerAddress,
            _swthAddress
        );

        bytes32 data = keccak256(
            abi.encodePacked(bytes1(0xff), address(this), salt, _bytecodeHash)
        );

        return address(bytes20(data << 96));
    }
// Solidity 0.6.12
/// @dev Add a contract as an extension
/// @param _argsBz the serialized ExtensionTxArgs
/// @param _fromChainId the originating chainId
/// @return true if success
function addExtension(
        bytes calldata _argsBz,
        bytes calldata /* _fromContractAddr */,
        uint64 _fromChainId
    )
        external
        onlyManagerContract
        nonReentrant
        returns (bool)
    {
        require(_fromChainId == counterpartChainId, "Invalid chain ID");

        ExtensionTxArgs memory args = _deserializeExtensionTxArgs(_argsBz);
        address extensionAddress = Utils.bytesToAddress(args.extensionAddress);
        extensions[extensionAddress] = true;

        return true;
    }
// Solidity 0.6.12
/// @dev Remove a contract from the extensions mapping
/// @param _argsBz the serialized ExtensionTxArgs
/// @param _fromChainId the originating chainId
/// @return true if success
function removeExtension(
        bytes calldata _argsBz,
        bytes calldata /* _fromContractAddr */,
        uint64 _fromChainId
    )
        external
        onlyManagerContract
        nonReentrant
        returns (bool)
    {
        require(_fromChainId == counterpartChainId, "Invalid chain ID");

        ExtensionTxArgs memory args = _deserializeExtensionTxArgs(_argsBz);
        address extensionAddress = Utils.bytesToAddress(args.extensionAddress);
        extensions[extensionAddress] = false;

        return true;
    }
// Solidity 0.6.12
/// @dev Marks an asset as registered by mapping the asset's address to
/// the specified _fromContractAddr and assetHash on Switcheo TradeHub
/// @param _argsBz the serialized RegisterAssetTxArgs
/// @param _fromContractAddr the associated contract address on Switcheo TradeHub
/// @param _fromChainId the originating chainId
/// @return true if success
function registerAsset(
        bytes calldata _argsBz,
        bytes calldata _fromContractAddr,
        uint64 _fromChainId
    )
        external
        onlyManagerContract
        nonReentrant
        returns (bool)
    {
        require(_fromChainId == counterpartChainId, "Invalid chain ID");

        RegisterAssetTxArgs memory args = _deserializeRegisterAssetTxArgs(_argsBz);
        _markAssetAsRegistered(
            Utils.bytesToAddress(args.nativeAssetHash),
            _fromContractAddr,
            args.assetHash
        );

        return true;
    }
// Solidity 0.6.12
/// @dev Performs a deposit from a Wallet contract
/// @param _walletAddress address of the wallet contract, the wallet contract
/// does not receive ETH in this call, but _walletAddress still needs to be payable
/// since the wallet contract can receive ETH, there would be compile errors otherwise
/// @param _assetHash the asset to deposit
/// @param _targetProxyHash the associated proxy hash on Switcheo TradeHub
/// @param _toAssetHash the associated asset hash on Switcheo TradeHub
/// @param _feeAddress the hex version of the Switcheo TradeHub address to send the fee to
/// @param _values[0]: amount, the number of tokens to deposit
/// @param _values[1]: feeAmount, the number of tokens to be used as fees
/// @param _values[2]: nonce, to prevent replay attacks
/// @param _values[3]: callAmount, some tokens may burn an amount before transfer
/// so we allow a callAmount to support these tokens
/// @param _v: the v value of the wallet owner's signature
/// @param _rs: the r, s values of the wallet owner's signature
function lockFromWallet(
        address payable _walletAddress,
        address _assetHash,
        bytes calldata _targetProxyHash,
        bytes calldata _toAssetHash,
        bytes calldata _feeAddress,
        uint256[] calldata _values,
        uint8 _v,
        bytes32[] calldata _rs
    )
        external
        nonReentrant
        returns (bool)
    {
        require(wallets[_walletAddress], "Invalid wallet address");

        Wallet wallet = Wallet(_walletAddress);
        _validateLockFromWallet(
            wallet.owner(),
            _assetHash,
            _targetProxyHash,
            _toAssetHash,
            _feeAddress,
            _values,
            _v,
            _rs
        );

        // it is very important that this function validates the success of a transfer correctly
        // since, once this line is passed, the deposit is assumed to be successful
        // which will eventually result in the specified amount of tokens being minted for the
        // wallet.swthAddress on Switcheo TradeHub
        _transferInFromWallet(_walletAddress, _assetHash, _values[0], _values[3]);

        _lock(
            _assetHash,
            _targetProxyHash,
            _toAssetHash,
            wallet.swthAddress(),
            _values[0],
            _values[1],
            _feeAddress
        );

        return true;
    }
// Solidity 0.6.12
/// @dev Performs a deposit
/// @param _assetHash the asset to deposit
/// @param _targetProxyHash the associated proxy hash on Switcheo TradeHub
/// @param _toAddress the hex version of the Switcheo TradeHub address to deposit to
/// @param _toAssetHash the associated asset hash on Switcheo TradeHub
/// @param _feeAddress the hex version of the Switcheo TradeHub address to send the fee to
/// @param _values[0]: amount, the number of tokens to deposit
/// @param _values[1]: feeAmount, the number of tokens to be used as fees
/// @param _values[2]: callAmount, some tokens may burn an amount before transfer
/// so we allow a callAmount to support these tokens
function lock(
        address _assetHash,
        bytes calldata _targetProxyHash,
        bytes calldata _toAddress,
        bytes calldata _toAssetHash,
        bytes calldata _feeAddress,
        uint256[] calldata _values
    )
        external
        payable
        nonReentrant
        returns (bool)
    {

        // it is very important that this function validates the success of a transfer correctly
        // since, once this line is passed, the deposit is assumed to be successful
        // which will eventually result in the specified amount of tokens being minted for the
        // _toAddress on Switcheo TradeHub
        _transferIn(_assetHash, _values[0], _values[2]);

        _lock(
            _assetHash,
            _targetProxyHash,
            _toAssetHash,
            _toAddress,
            _values[0],
            _values[1],
            _feeAddress
        );

        return true;
    }
// Solidity 0.6.12
/// @dev Performs a withdrawal that was initiated on Switcheo TradeHub
/// @param _argsBz the serialized TransferTxArgs
/// @param _fromContractAddr the associated contract address on Switcheo TradeHub
/// @param _fromChainId the originating chainId
/// @return true if success
function unlock(
        bytes calldata _argsBz,
        bytes calldata _fromContractAddr,
        uint64 _fromChainId
    )
        external
        onlyManagerContract
        nonReentrant
        returns (bool)
    {
        require(_fromChainId == counterpartChainId, "Invalid chain ID");

        TransferTxArgs memory args = _deserializeTransferTxArgs(_argsBz);
        require(args.fromAssetHash.length > 0, "Invalid fromAssetHash");
        require(args.toAssetHash.length == 20, "Invalid toAssetHash");

        address toAssetHash = Utils.bytesToAddress(args.toAssetHash);
        address toAddress = Utils.bytesToAddress(args.toAddress);

        _validateAssetRegistration(toAssetHash, _fromContractAddr, args.fromAssetHash);
        _transferOut(toAddress, toAssetHash, args.amount);

        emit UnlockEvent(toAssetHash, toAddress, args.amount, _argsBz);
        return true;
    }