MasterChefV2

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "remappings": []
  },
  "sources": {
    "ls.contracts/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-farms-pools/contracts/MasterChefV2.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
\r
pragma solidity 0.6.12;\r
pragma experimental ABIEncoderV2;\r
\r
import "./SSTBaseToken/contracts/access/Ownable.sol";\r
import "./SSTBaseToken/contracts/math/SafeMath.sol";\r
import "./utils/ReentrancyGuard.sol";\r
import "./SSTBaseToken/contracts/interfaces/IBEP20.sol";\r
import "./SSTBaseToken/contracts/SafeBEP20.sol";\r
import "./interfaces/IMasterChef.sol";\r
\r
/// @notice The (older) MasterChef contract gives out a constant number of CAKE tokens per block.\r
/// It is the only address with minting rights for CAKE.\r
/// The idea for this MasterChef V2 (MCV2) contract is therefore to be the owner of a dummy token\r
/// that is deposited into the MasterChef V1 (MCV1) contract.\r
/// The allocation point for this pool on MCV1 is the total allocation point for all pools that receive incentives.\r
contract MasterChefV2 is Ownable, ReentrancyGuard {\r
    using SafeMath for uint256;\r
    using SafeBEP20 for IBEP20;\r
\r
    /// @notice Info of each MCV2 user.\r
    /// `amount` LP token amount the user has provided.\r
    /// `rewardDebt` Used to calculate the correct amount of rewards. See explanation below.\r
    ///\r
    /// We do some fancy math here. Basically, any point in time, the amount of CAKEs\r
    /// entitled to a user but is pending to be distributed is:\r
    ///\r
    ///   pending reward = (user share * pool.accCakePerShare) - user.rewardDebt\r
    ///\r
    ///   Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\r
    ///   1. The pool's `accCakePerShare` (and `lastRewardBlock`) gets updated.\r
    ///   2. User receives the pending reward sent to his/her address.\r
    ///   3. User's `amount` gets updated. Pool's `totalBoostedShare` gets updated.\r
    ///   4. User's `rewardDebt` gets updated.\r
    struct UserInfo {\r
        uint256 amount;\r
        uint256 rewardDebt;\r
        uint256 boostMultiplier;\r
    }\r
\r
    /// @notice Info of each MCV2 pool.\r
    /// `allocPoint` The amount of allocation points assigned to the pool.\r
    ///     Also known as the amount of "multipliers". Combined with `totalXAllocPoint`, it defines the % of\r
    ///     CAKE rewards each pool gets.\r
    /// `accCakePerShare` Accumulated CAKEs per share, times 1e12.\r
    /// `lastRewardBlock` Last block number that pool update action is executed.\r
    /// `isRegular` The flag to set pool is regular or special. See below:\r
    ///     In MasterChef V2 farms are "regular pools". "special pools", which use a different sets of\r
    ///     `allocPoint` and their own `totalSpecialAllocPoint` are designed to handle the distribution of\r
    ///     the CAKE rewards to all the PancakeSwap products.\r
    /// `totalBoostedShare` The total amount of user shares in each pool. After considering the share boosts.\r
    struct PoolInfo {\r
        uint256 accCakePerShare;\r
        uint256 lastRewardBlock;\r
        uint256 allocPoint;\r
        uint256 totalBoostedShare;\r
        bool isRegular;\r
    }\r
\r
    /// @notice Address of MCV1 contract.\r
    IMasterChef public immutable MASTER_CHEF;\r
    /// @notice Address of CAKE contract.\r
    IBEP20 public immutable CAKE;\r
\r
    /// @notice The only address can withdraw all the burn CAKE.\r
    address public burnAdmin;\r
    /// @notice The contract handles the share boosts.\r
    address public boostContract;\r
\r
    /// @notice Info of each MCV2 pool.\r
    PoolInfo[] public poolInfo;\r
    /// @notice Address of the LP token for each MCV2 pool.\r
    IBEP20[] public lpToken;\r
\r
    /// @notice Info of each pool user.\r
    mapping(uint256 => mapping(address => UserInfo)) public userInfo;\r
    /// @notice The whitelist of addresses allowed to deposit in special pools.\r
    mapping(address => bool) public whiteList;\r
\r
    /// @notice The pool id of the MCV2 mock token pool in MCV1.\r
    uint256 public immutable MASTER_PID;\r
    /// @notice Total regular allocation points. Must be the sum of all regular pools' allocation points.\r
    uint256 public totalRegularAllocPoint;\r
    /// @notice Total special allocation points. Must be the sum of all special pools' allocation points.\r
    uint256 public totalSpecialAllocPoint;\r
    ///  @notice 40 cakes per block in MCV1\r
    uint256 public constant MASTERCHEF_CAKE_PER_BLOCK = 40 * 1e18;\r
    uint256 public constant ACC_CAKE_PRECISION = 1e18;\r
\r
    /// @notice Basic boost factor, none boosted user's boost factor\r
    uint256 public constant BOOST_PRECISION = 100 * 1e10;\r
    /// @notice Hard limit for maxmium boost factor, it must greater than BOOST_PRECISION\r
    uint256 public constant MAX_BOOST_PRECISION = 200 * 1e10;\r
    /// @notice total cake rate = toBurn + toRegular + toSpecial\r
    uint256 public constant CAKE_RATE_TOTAL_PRECISION = 1e12;\r
    /// @notice The last block number of CAKE burn action being executed.\r
    /// @notice CAKE distribute % for burn\r
    uint256 public cakeRateToBurn = 75 * 1e10;\r
    /// @notice CAKE distribute % for regular farm pool\r
    uint256 public cakeRateToRegularFarm = 10 * 1e10;\r
    /// @notice CAKE distribute % for special pools\r
    uint256 public cakeRateToSpecialFarm = 15 * 1e10;\r
\r
    uint256 public lastBurnedBlock;\r
\r
    event Init();\r
    event AddPool(uint256 indexed pid, uint256 allocPoint, IBEP20 indexed lpToken, bool isRegular);\r
    event SetPool(uint256 indexed pid, uint256 allocPoint);\r
    event UpdatePool(uint256 indexed pid, uint256 lastRewardBlock, uint256 lpSupply, uint256 accCakePerShare);\r
    event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\r
    event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\r
    event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\r
\r
    event UpdateCakeRate(uint256 burnRate, uint256 regularFarmRate, uint256 specialFarmRate);\r
    event UpdateBurnAdmin(address indexed oldAdmin, address indexed newAdmin);\r
    event UpdateWhiteList(address indexed user, bool isValid);\r
    event UpdateBoostContract(address indexed boostContract);\r
    event UpdateBoostMultiplier(address indexed user, uint256 oldMultiplier, uint256 newMultiplier);\r
\r
    /// @param _MASTER_CHEF The PancakeSwap MCV1 contract address.\r
    /// @param _CAKE The CAKE token contract address.\r
    /// @param _MASTER_PID The pool id of the dummy pool on the MCV1.\r
    /// @param _burnAdmin The address of burn admin.\r
    constructor(\r
        IMasterChef _MASTER_CHEF,\r
        IBEP20 _CAKE,\r
        uint256 _MASTER_PID,\r
        address _burnAdmin\r
    ) public {\r
        MASTER_CHEF = _MASTER_CHEF;\r
        CAKE = _CAKE;\r
        MASTER_PID = _MASTER_PID;\r
        burnAdmin = _burnAdmin;\r
    }\r
\r
    /**\r
     * @dev Throws if caller is not the boost contract.\r
     */\r
    modifier onlyBoostContract() {\r
        require(boostContract == msg.sender, "Ownable: caller is not the boost contract");\r
        _;\r
    }\r
\r
    /// @notice Deposits a dummy token to `MASTER_CHEF` MCV1. This is required because MCV1 holds the minting permission of CAKE.\r
    /// It will transfer all the `dummyToken` in the tx sender address.\r
    /// The allocation point for the dummy pool on MCV1 should be equal to the total amount of allocPoint.\r
    /// @param dummyToken The address of the BEP-20 token to be deposited into MCV1.\r
    function init(IBEP20 dummyToken) external onlyOwner {\r
        uint256 balance = dummyToken.balanceOf(msg.sender);\r
        require(balance != 0, "MasterChefV2: Balance must exceed 0");\r
        dummyToken.safeTransferFrom(msg.sender, address(this), balance);\r
        dummyToken.approve(address(MASTER_CHEF), balance);\r
        MASTER_CHEF.deposit(MASTER_PID, balance);\r
        // MCV2 start to earn CAKE reward from current block in MCV1 pool\r
        lastBurnedBlock = block.number;\r
        emit Init();\r
    }\r
\r
    /// @notice Returns the number of MCV2 pools.\r
    function poolLength() public view returns (uint256 pools) {\r
        pools = poolInfo.length;\r
    }\r
\r
    /// @notice Add a new pool. Can only be called by the owner.\r
    /// DO NOT add the same LP token more than once. Rewards will be messed up if you do.\r
    /// @param _allocPoint Number of allocation points for the new pool.\r
    /// @param _lpToken Address of the LP BEP-20 token.\r
    /// @param _isRegular Whether the pool is regular or special. LP farms are always "regular". "Special" pools are\r
    /// @param _withUpdate Whether call "massUpdatePools" operation.\r
    /// only for CAKE distributions within PancakeSwap products.\r
    function add(\r
        uint256 _allocPoint,\r
        IBEP20 _lpToken,\r
        bool _isRegular,\r
        bool _withUpdate\r
    ) external onlyOwner {\r
        require(_lpToken.balanceOf(address(this)) >= 0, "None BEP20 tokens");\r
        // stake CAKE token will cause staked token and reward token mixed up,\r
        // may cause staked tokens withdraw as reward token,never do it.\r
        require(_lpToken != CAKE, "CAKE token can't be added to farm pools");\r
\r
        if (_withUpdate) {\r
            massUpdatePools();\r
        }\r
\r
        if (_isRegular) {\r
            totalRegularAllocPoint = totalRegularAllocPoint.add(_allocPoint);\r
        } else {\r
            totalSpecialAllocPoint = totalSpecialAllocPoint.add(_allocPoint);\r
        }\r
        lpToken.push(_lpToken);\r
\r
        poolInfo.push(\r
            PoolInfo({\r
        allocPoint: _allocPoint,\r
        lastRewardBlock: block.number,\r
        accCakePerShare: 0,\r
        isRegular: _isRegular,\r
        totalBoostedShare: 0\r
        })\r
        );\r
        emit AddPool(lpToken.length.sub(1), _allocPoint, _lpToken, _isRegular);\r
    }\r
\r
    /// @notice Update the given pool's CAKE allocation point. Can only be called by the owner.\r
    /// @param _pid The id of the pool. See `poolInfo`.\r
    /// @param _allocPoint New number of allocation points for the pool.\r
    /// @param _withUpdate Whether call "massUpdatePools" operation.\r
    function set(\r
        uint256 _pid,\r
        uint256 _allocPoint,\r
        bool _withUpdate\r
    ) external onlyOwner {\r
        // No matter _withUpdate is true or false, we need to execute updatePool once before set the pool parameters.\r
        updatePool(_pid);\r
\r
        if (_withUpdate) {\r
            massUpdatePools();\r
        }\r
\r
        if (poolInfo[_pid].isRegular) {\r
            totalRegularAllocPoint = totalRegularAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\r
        } else {\r
            totalSpecialAllocPoint = totalSpecialAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\r
        }\r
        poolInfo[_pid].allocPoint = _allocPoint;\r
        emit SetPool(_pid, _allocPoint);\r
    }\r
\r
    /// @notice View function for checking pending CAKE rewards.\r
    /// @param _pid The id of the pool. See `poolInfo`.\r
    /// @param _user Address of the user.\r
    function pendingCake(uint256 _pid, address _user) external view returns (uint256) {\r
        PoolInfo memory pool = poolInfo[_pid];\r
        UserInfo memory user = userInfo[_pid][_user];\r
        uint256 accCakePerShare = pool.accCakePerShare;\r
        uint256 lpSupply = pool.totalBoostedShare;\r
\r
        if (block.number > pool.lastRewardBlock && lpSupply != 0) {\r
            uint256 multiplier = block.number.sub(pool.lastRewardBlock);\r
\r
            uint256 cakeReward = multiplier.mul(cakePerBlock(pool.isRegular)).mul(pool.allocPoint).div(\r
                (pool.isRegular ? totalRegularAllocPoint : totalSpecialAllocPoint)\r
            );\r
            accCakePerShare = accCakePerShare.add(cakeReward.mul(ACC_CAKE_PRECISION).div(lpSupply));\r
        }\r
\r
        uint256 boostedAmount = user.amount.mul(getBoostMultiplier(_user, _pid)).div(BOOST_PRECISION);\r
        return boostedAmount.mul(accCakePerShare).div(ACC_CAKE_PRECISION).sub(user.rewardDebt);\r
    }\r
\r
    /// @notice Update cake reward for all the active pools. Be careful of gas spending!\r
    function massUpdatePools() public {\r
        uint256 length = poolInfo.length;\r
        for (uint256 pid = 0; pid < length; ++pid) {\r
            PoolInfo memory pool = poolInfo[pid];\r
            if (pool.allocPoint != 0) {\r
                updatePool(pid);\r
            }\r
        }\r
    }\r
\r
    /// @notice Calculates and returns the `amount` of CAKE per block.\r
    /// @param _isRegular If the pool belongs to regular or special.\r
    function cakePerBlock(bool _isRegular) public view returns (uint256 amount) {\r
        if (_isRegular) {\r
            amount = MASTERCHEF_CAKE_PER_BLOCK.mul(cakeRateToRegularFarm).div(CAKE_RATE_TOTAL_PRECISION);\r
        } else {\r
            amount = MASTERCHEF_CAKE_PER_BLOCK.mul(cakeRateToSpecialFarm).div(CAKE_RATE_TOTAL_PRECISION);\r
        }\r
    }\r
\r
    /// @notice Calculates and returns the `amount` of CAKE per block to burn.\r
    function cakePerBlockToBurn() public view returns (uint256 amount) {\r
        amount = MASTERCHEF_CAKE_PER_BLOCK.mul(cakeRateToBurn).div(CAKE_RATE_TOTAL_PRECISION);\r
    }\r
\r
    /// @notice Update reward variables for the given pool.\r
    /// @param _pid The id of the pool. See `poolInfo`.\r
    /// @return pool Returns the pool that was updated.\r
    function updatePool(uint256 _pid) public returns (PoolInfo memory pool) {\r
        pool = poolInfo[_pid];\r
        if (block.number > pool.lastRewardBlock) {\r
            uint256 lpSupply = pool.totalBoostedShare;\r
            uint256 totalAllocPoint = (pool.isRegular ? totalRegularAllocPoint : totalSpecialAllocPoint);\r
\r
            if (lpSupply > 0 && totalAllocPoint > 0) {\r
                uint256 multiplier = block.number.sub(pool.lastRewardBlock);\r
                uint256 cakeReward = multiplier.mul(cakePerBlock(pool.isRegular)).mul(pool.allocPoint).div(\r
                    totalAllocPoint\r
                );\r
                pool.accCakePerShare = pool.accCakePerShare.add((cakeReward.mul(ACC_CAKE_PRECISION).div(lpSupply)));\r
            }\r
            pool.lastRewardBlock = block.number;\r
            poolInfo[_pid] = pool;\r
            emit UpdatePool(_pid, pool.lastRewardBlock, lpSupply, pool.accCakePerShare);\r
        }\r
    }\r
\r
    /// @notice Deposit LP tokens to pool.\r
    /// @param _pid The id of the pool. See `poolInfo`.\r
    /// @param _amount Amount of LP tokens to deposit.\r
    function deposit(uint256 _pid, uint256 _amount) external nonReentrant {\r
        PoolInfo memory pool = updatePool(_pid);\r
        UserInfo storage user = userInfo[_pid][msg.sender];\r
\r
        require(\r
            pool.isRegular || whiteList[msg.sender],\r
            "MasterChefV2: The address is not available to deposit in this pool"\r
        );\r
\r
        uint256 multiplier = getBoostMultiplier(msg.sender, _pid);\r
\r
        if (user.amount > 0) {\r
            settlePendingCake(msg.sender, _pid, multiplier);\r
        }\r
\r
        if (_amount > 0) {\r
            uint256 before = lpToken[_pid].balanceOf(address(this));\r
            lpToken[_pid].safeTransferFrom(msg.sender, address(this), _amount);\r
            _amount = lpToken[_pid].balanceOf(address(this)).sub(before);\r
            user.amount = user.amount.add(_amount);\r
\r
            // Update total boosted share.\r
            pool.totalBoostedShare = pool.totalBoostedShare.add(_amount.mul(multiplier).div(BOOST_PRECISION));\r
        }\r
\r
        user.rewardDebt = user.amount.mul(multiplier).div(BOOST_PRECISION).mul(pool.accCakePerShare).div(\r
            ACC_CAKE_PRECISION\r
        );\r
        poolInfo[_pid] = pool;\r
\r
        emit Deposit(msg.sender, _pid, _amount);\r
    }\r
\r
    /// @notice Withdraw LP tokens from pool.\r
    /// @param _pid The id of the pool. See `poolInfo`.\r
    /// @param _amount Amount of LP tokens to withdraw.\r
    function withdraw(uint256 _pid, uint256 _amount) external nonReentrant {\r
        PoolInfo memory pool = updatePool(_pid);\r
        UserInfo storage user = userInfo[_pid][msg.sender];\r
\r
        require(user.amount >= _amount, "withdraw: Insufficient");\r
\r
        uint256 multiplier = getBoostMultiplier(msg.sender, _pid);\r
\r
        settlePendingCake(msg.sender, _pid, multiplier);\r
\r
        if (_amount > 0) {\r
            user.amount = user.amount.sub(_amount);\r
            lpToken[_pid].safeTransfer(msg.sender, _amount);\r
        }\r
\r
        user.rewardDebt = user.amount.mul(multiplier).div(BOOST_PRECISION).mul(pool.accCakePerShare).div(\r
            ACC_CAKE_PRECISION\r
        );\r
        poolInfo[_pid].totalBoostedShare = poolInfo[_pid].totalBoostedShare.sub(\r
            _amount.mul(multiplier).div(BOOST_PRECISION)\r
        );\r
\r
        emit Withdraw(msg.sender, _pid, _amount);\r
    }\r
\r
    /// @notice Harvests CAKE from `MASTER_CHEF` MCV1 and pool `MASTER_PID` to MCV2.\r
    function harvestFromMasterChef() public {\r
        MASTER_CHEF.deposit(MASTER_PID, 0);\r
    }\r
\r
    /// @notice Withdraw without caring about the rewards. EMERGENCY ONLY.\r
    /// @param _pid The id of the pool. See `poolInfo`.\r
    function emergencyWithdraw(uint256 _pid) external nonReentrant {\r
        PoolInfo storage pool = poolInfo[_pid];\r
        UserInfo storage user = userInfo[_pid][msg.sender];\r
\r
        uint256 amount = user.amount;\r
        user.amount = 0;\r
        user.rewardDebt = 0;\r
        uint256 boostedAmount = amount.mul(getBoostMultiplier(msg.sender, _pid)).div(BOOST_PRECISION);\r
        pool.totalBoostedShare = pool.totalBoostedShare > boostedAmount ? pool.totalBoostedShare.sub(boostedAmount) : 0;\r
\r
        // Note: transfer can fail or succeed if `amount` is zero.\r
        lpToken[_pid].safeTransfer(msg.sender, amount);\r
        emit EmergencyWithdraw(msg.sender, _pid, amount);\r
    }\r
\r
    /// @notice Send CAKE pending for burn to `burnAdmin`.\r
    /// @param _withUpdate Whether call "massUpdatePools" operation.\r
    function burnCake(bool _withUpdate) public onlyOwner {\r
        if (_withUpdate) {\r
            massUpdatePools();\r
        }\r
\r
        uint256 multiplier = block.number.sub(lastBurnedBlock);\r
        uint256 pendingCakeToBurn = multiplier.mul(cakePerBlockToBurn());\r
\r
        // SafeTransfer CAKE\r
        _safeTransfer(burnAdmin, pendingCakeToBurn);\r
        lastBurnedBlock = block.number;\r
    }\r
\r
    /// @notice Update the % of CAKE distributions for burn, regular pools and special pools.\r
    /// @param _burnRate The % of CAKE to burn each block.\r
    /// @param _regularFarmRate The % of CAKE to regular pools each block.\r
    /// @param _specialFarmRate The % of CAKE to special pools each block.\r
    /// @param _withUpdate Whether call "massUpdatePools" operation.\r
    function updateCakeRate(\r
        uint256 _burnRate,\r
        uint256 _regularFarmRate,\r
        uint256 _specialFarmRate,\r
        bool _withUpdate\r
    ) external onlyOwner {\r
        require(\r
            _burnRate > 0 && _regularFarmRate > 0 && _specialFarmRate > 0,\r
            "MasterChefV2: Cake rate must be greater than 0"\r
        );\r
        require(\r
            _burnRate.add(_regularFarmRate).add(_specialFarmRate) == CAKE_RATE_TOTAL_PRECISION,\r
            "MasterChefV2: Total rate must be 1e12"\r
        );\r
        if (_withUpdate) {\r
            massUpdatePools();\r
        }\r
        // burn cake base on old burn cake rate\r
        burnCake(false);\r
\r
        cakeRateToBurn = _burnRate;\r
        cakeRateToRegularFarm = _regularFarmRate;\r
        cakeRateToSpecialFarm = _specialFarmRate;\r
\r
        emit UpdateCakeRate(_burnRate, _regularFarmRate, _specialFarmRate);\r
    }\r
\r
    /// @notice Update burn admin address.\r
    /// @param _newAdmin The new burn admin address.\r
    function updateBurnAdmin(address _newAdmin) external onlyOwner {\r
        require(_newAdmin != address(0), "MasterChefV2: Burn admin address must be valid");\r
        require(_newAdmin != burnAdmin, "MasterChefV2: Burn admin address is the same with current address");\r
        address _oldAdmin = burnAdmin;\r
        burnAdmin = _newAdmin;\r
        emit UpdateBurnAdmin(_oldAdmin, _newAdmin);\r
    }\r
\r
    /// @notice Update whitelisted addresses for special pools.\r
    /// @param _user The address to be updated.\r
    /// @param _isValid The flag for valid or invalid.\r
    function updateWhiteList(address _user, bool _isValid) external onlyOwner {\r
        require(_user != address(0), "MasterChefV2: The white list address must be valid");\r
\r
        whiteList[_user] = _isValid;\r
        emit UpdateWhiteList(_user, _isValid);\r
    }\r
\r
    /// @notice Update boost contract address and max boost factor.\r
    /// @param _newBoostContract The new address for handling all the share boosts.\r
    function updateBoostContract(address _newBoostContract) external onlyOwner {\r
        require(\r
            _newBoostContract != address(0) && _newBoostContract != boostContract,\r
            "MasterChefV2: New boost contract address must be valid"\r
        );\r
\r
        boostContract = _newBoostContract;\r
        emit UpdateBoostContract(_newBoostContract);\r
    }\r
\r
    /// @notice Update user boost factor.\r
    /// @param _user The user address for boost factor updates.\r
    /// @param _pid The pool id for the boost factor updates.\r
    /// @param _newMultiplier New boost multiplier.\r
    function updateBoostMultiplier(\r
        address _user,\r
        uint256 _pid,\r
        uint256 _newMultiplier\r
    ) external onlyBoostContract nonReentrant {\r
        require(_user != address(0), "MasterChefV2: The user address must be valid");\r
        require(poolInfo[_pid].isRegular, "MasterChefV2: Only regular farm could be boosted");\r
        require(\r
            _newMultiplier >= BOOST_PRECISION && _newMultiplier <= MAX_BOOST_PRECISION,\r
            "MasterChefV2: Invalid new boost multiplier"\r
        );\r
\r
        PoolInfo memory pool = updatePool(_pid);\r
        UserInfo storage user = userInfo[_pid][_user];\r
\r
        uint256 prevMultiplier = getBoostMultiplier(_user, _pid);\r
        settlePendingCake(_user, _pid, prevMultiplier);\r
\r
        user.rewardDebt = user.amount.mul(_newMultiplier).div(BOOST_PRECISION).mul(pool.accCakePerShare).div(\r
            ACC_CAKE_PRECISION\r
        );\r
        pool.totalBoostedShare = pool.totalBoostedShare.sub(user.amount.mul(prevMultiplier).div(BOOST_PRECISION)).add(\r
            user.amount.mul(_newMultiplier).div(BOOST_PRECISION)\r
        );\r
        poolInfo[_pid] = pool;\r
        userInfo[_pid][_user].boostMultiplier = _newMultiplier;\r
\r
        emit UpdateBoostMultiplier(_user, prevMultiplier, _newMultiplier);\r
    }\r
\r
    /// @notice Get user boost multiplier for specific pool id.\r
    /// @param _user The user address.\r
    /// @param _pid The pool id.\r
    function getBoostMultiplier(address _user, uint256 _pid) public view returns (uint256) {\r
        uint256 multiplier = userInfo[_pid][_user].boostMultiplier;\r
        return multiplier > BOOST_PRECISION ? multiplier : BOOST_PRECISION;\r
    }\r
\r
    /// @notice Settles, distribute the pending CAKE rewards for given user.\r
    /// @param _user The user address for settling rewards.\r
    /// @param _pid The pool id.\r
    /// @param _boostMultiplier The user boost multiplier in specific pool id.\r
    function settlePendingCake(\r
        address _user,\r
        uint256 _pid,\r
        uint256 _boostMultiplier\r
    ) internal {\r
        UserInfo memory user = userInfo[_pid][_user];\r
\r
        uint256 boostedAmount = user.amount.mul(_boostMultiplier).div(BOOST_PRECISION);\r
        uint256 accCake = boostedAmount.mul(poolInfo[_pid].accCakePerShare).div(ACC_CAKE_PRECISION);\r
        uint256 pending = accCake.sub(user.rewardDebt);\r
        // SafeTransfer CAKE\r
        _safeTransfer(_user, pending);\r
    }\r
\r
    /// @notice Safe Transfer CAKE.\r
    /// @param _to The CAKE receiver address.\r
    /// @param _amount transfer CAKE amounts.\r
    function _safeTransfer(address _to, uint256 _amount) internal {\r
        if (_amount > 0) {\r
            // Check whether MCV2 has enough CAKE. If not, harvest from MCV1.\r
            if (CAKE.balanceOf(address(this)) < _amount) {\r
                harvestFromMasterChef();\r
            }\r
            uint256 balance = CAKE.balanceOf(address(this));\r
            if (balance < _amount) {\r
                _amount = balance;\r
            }\r
            CAKE.safeTransfer(_to, _amount);\r
        }\r
    }\r
}"
    },
    "ls.contracts/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-farms-pools/contracts/interfaces/IMasterChef.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
pragma solidity 0.6.12;\r
\r
interface IMasterChef {\r
    function deposit(uint256 _pid, uint256 _amount) external;\r
\r
    function withdraw(uint256 _pid, uint256 _amount) external;\r
\r
    function enterStaking(uint256 _amount) external;\r
\r
    function leaveStaking(uint256 _amount) external;\r
\r
    function pendingCake(uint256 _pid, address _user) external view returns (uint256);\r
\r
    function userInfo(uint256 _pid, address _user) external view returns (uint256, uint256);\r
\r
    function emergencyWithdraw(uint256 _pid) external;\r
}"
    },
    "ls.contracts/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-farms-pools/contracts/SSTBaseToken/contracts/SafeBEP20.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
pragma solidity ^0.6.0;\r
\r
import "./interfaces/IBEP20.sol";\r
import "./utils/Address.sol";\r
import "./math/SafeMath.sol";\r
\r
/**\r
 * @title SafeBEP20\r
 * @dev Wrappers around BEP20 operations that throw on failure (when the token\r
 * contract returns false). Tokens that return no value (and instead revert or\r
 * throw on failure) are also supported, non-reverting calls are assumed to be\r
 * successful.\r
 * To use this library you can add a `using SafeBEP20 for IBEP20;` statement to your contract,\r
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\r
 */\r
library SafeBEP20 {\r
  using SafeMath for uint256;\r
  using Address for address;\r
\r
  function safeTransfer(\r
    IBEP20 token,\r
    address to,\r
    uint256 value\r
  ) internal {\r
    _callOptionalReturn(\r
      token,\r
      abi.encodeWithSelector(token.transfer.selector, to, value)\r
    );\r
  }\r
\r
  function safeTransferFrom(\r
    IBEP20 token,\r
    address from,\r
    address to,\r
    uint256 value\r
  ) internal {\r
    _callOptionalReturn(\r
      token,\r
      abi.encodeWithSelector(token.transferFrom.selector, from, to, value)\r
    );\r
  }\r
\r
  /**\r
   * @dev Deprecated. This function has issues similar to the ones found in\r
   * {IBEP20-approve}, and its usage is discouraged.\r
   *\r
   * Whenever possible, use {safeIncreaseAllowance} and\r
   * {safeDecreaseAllowance} instead.\r
   */\r
  function safeApprove(\r
    IBEP20 token,\r
    address spender,\r
    uint256 value\r
  ) internal {\r
    // safeApprove should only be called when setting an initial allowance,\r
    // or when resetting it to zero. To increase and decrease it, use\r
    // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\r
    // solhint-disable-next-line max-line-length\r
    require(\r
      (value == 0) || (token.allowance(address(this), spender) == 0),\r
      "SafeBEP20: approve from non-zero to non-zero allowance"\r
    );\r
    _callOptionalReturn(\r
      token,\r
      abi.encodeWithSelector(token.approve.selector, spender, value)\r
    );\r
  }\r
\r
  function safeIncreaseAllowance(\r
    IBEP20 token,\r
    address spender,\r
    uint256 value\r
  ) internal {\r
    uint256 newAllowance = token.allowance(address(this), spender).add(value);\r
    _callOptionalReturn(\r
      token,\r
      abi.encodeWithSelector(token.approve.selector, spender, newAllowance)\r
    );\r
  }\r
\r
  function safeDecreaseAllowance(\r
    IBEP20 token,\r
    address spender,\r
    uint256 value\r
  ) internal {\r
    uint256 newAllowance =\r
      token.allowance(address(this), spender).sub(\r
        value,\r
        "SafeBEP20: decreased allowance below zero"\r
      );\r
    _callOptionalReturn(\r
      token,\r
      abi.encodeWithSelector(token.approve.selector, spender, newAllowance)\r
    );\r
  }\r
\r
  /**\r
   * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\r
   * on the return value: the return value is optional (but if data is returned, it must not be false).\r
   * @param token The token targeted by the call.\r
   * @param data The call data (encoded using abi.encode or one of its variants).\r
   */\r
  function _callOptionalReturn(IBEP20 token, bytes memory data) private {\r
    // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\r
    // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\r
    // the target address contains contract code and also asserts for success in the low-level call.\r
\r
    bytes memory returndata =\r
      address(token).functionCall(data, "SafeBEP20: low-level call failed");\r
    if (returndata.length > 0) {\r
      // Return data is optional\r
      // solhint-disable-next-line max-line-length\r
      require(\r
        abi.decode(returndata, (bool)),\r
        "SafeBEP20: BEP20 operation did not succeed"\r
      );\r
    }\r
  }\r
}\r
"
    },
    "ls.contracts/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-farms-pools/contracts/SSTBaseToken/contracts/interfaces/IBEP20.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
\r
pragma solidity >=0.4.0;\r
\r
interface IBEP20 {\r
  /**\r
   * @dev Returns the amount of tokens in existence.\r
   */\r
  function totalSupply() external view returns (uint256);\r
\r
  /**\r
   * @dev Returns the token decimals.\r
   */\r
  function decimals() external view returns (uint8);\r
\r
  /**\r
   * @dev Returns the token symbol.\r
   */\r
  function symbol() external view returns (string memory);\r
\r
  /**\r
   * @dev Returns the token name.\r
   */\r
  function name() external view returns (string memory);\r
\r
  /**\r
   * @dev Returns the bep token owner.\r
   */\r
  function getOwner() external view returns (address);\r
\r
  /**\r
   * @dev Returns the amount of tokens owned by `account`.\r
   */\r
  function balanceOf(address account) external view returns (uint256);\r
\r
  /**\r
   * @dev Moves `amount` tokens from the caller's account to `recipient`.\r
   *\r
   * Returns a boolean value indicating whether the operation succeeded.\r
   *\r
   * Emits a {Transfer} event.\r
   */\r
  function transfer(address recipient, uint256 amount) external returns (bool);\r
\r
  /**\r
   * @dev Returns the remaining number of tokens that `spender` will be\r
   * allowed to spend on behalf of `owner` through {transferFrom}. This is\r
   * zero by default.\r
   *\r
   * This value changes when {approve} or {transferFrom} are called.\r
   */\r
  function allowance(address _owner, address spender)\r
    external\r
    view\r
    returns (uint256);\r
\r
  /**\r
   * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\r
   *\r
   * Returns a boolean value indicating whether the operation succeeded.\r
   *\r
   * IMPORTANT: Beware that changing an allowance with this method brings the risk\r
   * that someone may use both the old and the new allowance by unfortunate\r
   * transaction ordering. One possible solution to mitigate this race\r
   * condition is to first reduce the spender's allowance to 0 and set the\r
   * desired value afterwards:\r
   * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\r
   *\r
   * Emits an {Approval} event.\r
   */\r
  function approve(address spender, uint256 amount) external returns (bool);\r
\r
  /**\r
   * @dev Moves `amount` tokens from `sender` to `recipient` using the\r
   * allowance mechanism. `amount` is then deducted from the caller's\r
   * allowance.\r
   *\r
   * Returns a boolean value indicating whether the operation succeeded.\r
   *\r
   * Emits a {Transfer} event.\r
   */\r
  function transferFrom(\r
    address sender,\r
    address recipient,\r
    uint256 amount\r
  ) external returns (bool);\r
\r
  /**\r
   * @dev Emitted when `value` tokens are moved from one account (`from`) to\r
   * another (`to`).\r
   *\r
   * Note that `value` may be zero.\r
   */\r
  event Transfer(address indexed from, address indexed to, uint256 value);\r
\r
  /**\r
   * @dev Emitted when the allowance of a `spender` for an `owner` is set by\r
   * a call to {approve}. `value` is the new allowance.\r
   */\r
  event Approval(address indexed owner, address indexed spender, uint256 value);\r
}\r
"
    },
    "ls.contracts/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-farms-pools/contracts/utils/ReentrancyGuard.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
\r
pragma solidity ^0.6.0;\r
\r
/**\r
 * @dev Contract module that helps prevent reentrant calls to a function.\r
 *\r
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\r
 * available, which can be applied to functions to make sure there are no nested\r
 * (reentrant) calls to them.\r
 *\r
 * Note that because there is a single `nonReentrant` guard, functions marked as\r
 * `nonReentrant` may not call one another. This can be worked around by making\r
 * those functions `private`, and then adding `external` `nonReentrant` entry\r
 * points to them.\r
 *\r
 * TIP: If you would like to learn more about reentrancy and alternative ways\r
 * to protect against it, check out our blog post\r
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\r
 */\r
contract ReentrancyGuard {\r
    // Booleans are more expensive than uint256 or any type that takes up a full\r
    // word because each write operation emits an extra SLOAD to first read the\r
    // slot's contents, replace the bits taken up by the boolean, and then write\r
    // back. This is the compiler's defense against contract upgrades and\r
    // pointer aliasing, and it cannot be disabled.\r
\r
    // The values being non-zero value makes deployment a bit more expensive,\r
    // but in exchange the refund on every call to nonReentrant will be lower in\r
    // amount. Since refunds are capped to a percentage of the total\r
    // transaction's gas, it is best to keep them low in cases like this one, to\r
    // increase the likelihood of the full refund coming into effect.\r
    uint256 private constant _NOT_ENTERED = 1;\r
    uint256 private constant _ENTERED = 2;\r
\r
    uint256 private _status;\r
\r
    constructor () internal {\r
        _status = _NOT_ENTERED;\r
    }\r
\r
    /**\r
     * @dev Prevents a contract from calling itself, directly or indirectly.\r
     * Calling a `nonReentrant` function from another `nonReentrant`\r
     * function is not supported. It is possible to prevent this from happening\r
     * by making the `nonReentrant` function external, and make it call a\r
     * `private` function that does the actual work.\r
     */\r
    modifier nonReentrant() {\r
        // On the first call to nonReentrant, _notEntered will be true\r
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");\r
\r
        // Any calls to nonReentrant after this point will fail\r
        _status = _ENTERED;\r
\r
        _;\r
\r
        // By storing the original value once again, a refund is triggered (see\r
        // https://eips.ethereum.org/EIPS/eip-2200)\r
        _status = _NOT_ENTERED;\r
    }\r
}"
    },
    "ls.contracts/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-farms-pools/contracts/SSTBaseToken/contracts/math/SafeMath.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
\r
pragma solidity ^0.6.0;\r
\r
/**\r
 * @dev Wrappers over Solidity's arithmetic operations with added overflow\r
 * checks.\r
 *\r
 * Arithmetic operations in Solidity wrap on overflow. This can easily result\r
 * in bugs, because programmers usually assume that an overflow raises an\r
 * error, which is the standard behavior in high level programming languages.\r
 * `SafeMath` restores this intuition by reverting the transaction when an\r
 * operation overflows.\r
 *\r
 * Using this library instead of the unchecked operations eliminates an entire\r
 * class of bugs, so it's recommended to use it always.\r
 */\r
library SafeMath {\r
    /**\r
     * @dev Returns the addition of two unsigned integers, reverting on\r
     * overflow.\r
     *\r
     * Counterpart to Solidity's `+` operator.\r
     *\r
     * Requirements:\r
     *\r
     * - Addition cannot overflow.\r
     */\r
    function add(uint256 a, uint256 b) internal pure returns (uint256) {\r
        uint256 c = a + b;\r
        require(c >= a, "SafeMath: addition overflow");\r
\r
        return c;\r
    }\r
\r
    /**\r
     * @dev Returns the subtraction of two unsigned integers, reverting on\r
     * overflow (when the result is negative).\r
     *\r
     * Counterpart to Solidity's `-` operator.\r
     *\r
     * Requirements:\r
     *\r
     * - Subtraction cannot overflow.\r
     */\r
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\r
        return sub(a, b, "SafeMath: subtraction overflow");\r
    }\r
\r
    /**\r
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\r
     * overflow (when the result is negative).\r
     *\r
     * Counterpart to Solidity's `-` operator.\r
     *\r
     * Requirements:\r
     *\r
     * - Subtraction cannot overflow.\r
     */\r
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r
        require(b <= a, errorMessage);\r
        uint256 c = a - b;\r
\r
        return c;\r
    }\r
\r
    /**\r
     * @dev Returns the multiplication of two unsigned integers, reverting on\r
     * overflow.\r
     *\r
     * Counterpart to Solidity's `*` operator.\r
     *\r
     * Requirements:\r
     *\r
     * - Multiplication cannot overflow.\r
     */\r
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\r
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\r
        // benefit is lost if 'b' is also tested.\r
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\r
        if (a == 0) {\r
            return 0;\r
        }\r
\r
        uint256 c = a * b;\r
        require(c / a == b, "SafeMath: multiplication overflow");\r
\r
        return c;\r
    }\r
\r
    /**\r
     * @dev Returns the integer division of two unsigned integers. Reverts on\r
     * division by zero. The result is rounded towards zero.\r
     *\r
     * Counterpart to Solidity's `/` operator. Note: this function uses a\r
     * `revert` opcode (which leaves remaining gas untouched) while Solidity\r
     * uses an invalid opcode to revert (consuming all remaining gas).\r
     *\r
     * Requirements:\r
     *\r
     * - The divisor cannot be zero.\r
     */\r
    function div(uint256 a, uint256 b) internal pure returns (uint256) {\r
        return div(a, b, "SafeMath: division by zero");\r
    }\r
\r
    /**\r
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\r
     * division by zero. The result is rounded towards zero.\r
     *\r
     * Counterpart to Solidity's `/` operator. Note: this function uses a\r
     * `revert` opcode (which leaves remaining gas untouched) while Solidity\r
     * uses an invalid opcode to revert (consuming all remaining gas).\r
     *\r
     * Requirements:\r
     *\r
     * - The divisor cannot be zero.\r
     */\r
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r
        require(b > 0, errorMessage);\r
        uint256 c = a / b;\r
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold\r
\r
        return c;\r
    }\r
\r
    /**\r
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r
     * Reverts when dividing by zero.\r
     *\r
     * Counterpart to Solidity's `%` operator. This function uses a `revert`\r
     * opcode (which leaves remaining gas untouched) while Solidity uses an\r
     * invalid opcode to revert (consuming all remaining gas).\r
     *\r
     * Requirements:\r
     *\r
     * - The divisor cannot be zero.\r
     */\r
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\r
        return mod(a, b, "SafeMath: modulo by zero");\r
    }\r
\r
    /**\r
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r
     * Reverts with custom message when dividing by zero.\r
     *\r
     * Counterpart to Solidity's `%` operator. This function uses a `revert`\r
     * opcode (which leaves remaining gas untouched) while Solidity uses an\r
     * invalid opcode to revert (consuming all remaining gas).\r
     *\r
     * Requirements:\r
     *\r
     * - The divisor cannot be zero.\r
     */\r
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r
        require(b != 0, errorMessage);\r
        return a % b;\r
    }\r
}"
    },
    "ls.contracts/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-farms-pools/contracts/SSTBaseToken/contracts/access/Ownable.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
\r
pragma solidity ^0.6.0;\r
\r
import "../GSN/Context.sol";\r
/**\r
 * @dev Contract module which provides a basic access control mechanism, where\r
 * there is an account (an owner) that can be granted exclusive access to\r
 * specific functions.\r
 *\r
 * By default, the owner account will be the one that deploys the contract. This\r
 * can later be changed with {transferOwnership}.\r
 *\r
 * This module is used through inheritance. It will make available the modifier\r
 * `onlyOwner`, which can be applied to your functions to restrict their use to\r
 * the owner.\r
 */\r
contract Ownable is Context {\r
    address private _owner;\r
\r
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r
\r
    /**\r
     * @dev Initializes the contract setting the deployer as the initial owner.\r
     */\r
    constructor () internal {\r
        address msgSender = _msgSender();\r
        _owner = msgSender;\r
        emit OwnershipTransferred(address(0), msgSender);\r
    }\r
\r
    /**\r
     * @dev Returns the address of the current owner.\r
     */\r
    function owner() public view returns (address) {\r
        return _owner;\r
    }\r
\r
    /**\r
     * @dev Throws if called by any account other than the owner.\r
     */\r
    modifier onlyOwner() {\r
        require(_owner == _msgSender(), "Ownable: caller is not the owner");\r
        _;\r
    }\r
\r
    /**\r
     * @dev Leaves the contract without owner. It will not be possible to call\r
     * `onlyOwner` functions anymore. Can only be called by the current owner.\r
     *\r
     * NOTE: Renouncing ownership will leave the contract without an owner,\r
     * thereby removing any functionality that is only available to the owner.\r
     */\r
    function renounceOwnership() public virtual onlyOwner {\r
        emit OwnershipTransferred(_owner, address(0));\r
        _owner = address(0);\r
    }\r
\r
    /**\r
     * @dev Transfers ownership of the contract to a new account (`newOwner`).\r
     * Can only be called by the current owner.\r
     */\r
    function transferOwnership(address newOwner) public virtual onlyOwner {\r
        require(newOwner != address(0), "Ownable: new owner is the zero address");\r
        emit OwnershipTransferred(_owner, newOwner);\r
        _owner = newOwner;\r
    }\r
}"
    },
    "ls.contracts/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-farms-pools/contracts/SSTBaseToken/contracts/GSN/Context.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
\r
pragma solidity ^0.6.0;\r
\r
/*\r
 * @dev Provides information about the current execution context, including the\r
 * sender of the transaction and its data. While these are generally available\r
 * via msg.sender and msg.data, they should not be accessed in such a direct\r
 * manner, since when dealing with GSN meta-transactions the account sending and\r
 * paying for execution may not be the actual sender (as far as an application\r
 * is concerned).\r
 *\r
 * This contract is only required for intermediate, library-like contracts.\r
 */\r
abstract contract Context {\r
    function _msgSender() internal view virtual returns (address payable) {\r
        return msg.sender;\r
    }\r
\r
    function _msgData() internal view virtual returns (bytes memory) {\r
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\r
        return msg.data;\r
    }\r
}"
    },
    "ls.contracts/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-Token-Router-Factory-Farms-Contracts-/SwapStream-farms-pools/contracts/SSTBaseToken/contracts/utils/Address.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
\r
pragma solidity ^0.6.2;\r
\r
/**\r
 * @dev Collection of functions related to the address type\r
 */\r
library Address {\r
    /**\r
     * @dev Returns true if `account` is a contract.\r
     *\r
     * [IMPORTANT]\r
     * ====\r
     * It is unsafe to assume that an address for which this function returns\r
     * false is an externally-owned account (EOA) and not a contract.\r
     *\r
     * Among others, `isContract` will return false for the following\r
     * types of addresses:\r
     *\r
     *  - an externally-owned account\r
     *  - a contract in construction\r
     *  - an address where a contract will be created\r
     *  - an address where a contract lived, but was destroyed\r
     * ====\r
     */\r
    function isContract(address account) internal view returns (bool) {\r
        // This method relies in extcodesize, which returns 0 for contracts in\r
        // construction, since the code is only stored at the end of the\r
        // constructor execution.\r
\r
        uint256 size;\r
        // solhint-disable-next-line no-inline-assembly\r
        assembly { size := extcodesize(account) }\r
        return size > 0;\r
    }\r
\r
    /**\r
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\r
     * `recipient`, forwarding all available gas and reverting on errors.\r
     *\r
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r
     * of certain opcodes, possibly making contracts go over the 2300 gas limit\r
     * imposed by `transfer`, making them unable to receive funds via\r
     * `transfer`. {sendValue} removes this limitation.\r
     *\r
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r
     *\r
     * IMPORTANT: because control is transferred to `recipient`, care must be\r
     * taken to not create reentrancy vulnerabilities. Consider using\r
     * {ReentrancyGuard} or the\r
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r
     */\r
    function sendValue(address payable recipient, uint256 amount) internal {\r
        require(address(this).balance >= amount, "Address: insufficient balance");\r
\r
        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\r
        (bool success, ) = recipient.call{ value: amount }("");\r
        require(success, "Address: unable to send value, recipient may have reverted");\r
    }\r
\r
    /**\r
     * @dev Performs a Solidity function call using a low level `call`. A\r
     * plain`call` is an unsafe replacement for a function call: use this\r
     * function instead.\r
     *\r
     * If `target` reverts with a revert reason, it is bubbled up by this\r
     * function (like regular Solidity function calls).\r
     *\r
     * Returns the raw returned data. To convert to the expected return value,\r
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r
     *\r
     * Requirements:\r
     *\r
     * - `target` must be a contract.\r
     * - calling `target` with `data` must not revert.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\r
      return functionCall(target, data, "Address: low-level call failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r
     * `errorMessage` as a fallback revert reason when `target` reverts.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\r
        return _functionCallWithValue(target, data, 0, errorMessage);\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r
     * but also transferring `value` wei to `target`.\r
     *\r
     * Requirements:\r
     *\r
     * - the calling contract must have an ETH balance of at least `value`.\r
     * - the called Solidity function must be `payable`.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\r
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");\r
    }\r
\r
    /**\r
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r
     * with `errorMessage` as a fallback revert reason when `target` reverts.\r
     *\r
     * _Available since v3.1._\r
     */\r
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\r
        require(address(this).balance >= value, "Address: insufficient balance for call");\r
        return _functionCallWithValue(target, data, value, errorMessage);\r
    }\r
\r
    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {\r
        require(isContract(target), "Address: call to non-contract");\r
\r
        // solhint-disable-next-line avoid-low-level-calls\r
        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);\r
        if (success) {\r
            return returndata;\r
        } else {\r
            // Look for revert reason and bubble it up if present\r
            if (returndata.length > 0) {\r
                // The easiest way to bubble the revert reason is using memory via assembly\r
\r
                // solhint-disable-next-line no-inline-assembly\r
                assembly {\r
                    let returndata_size := mload(returndata)\r
                    revert(add(32, returndata), returndata_size)\r
                }\r
            } else {\r
                revert(errorMessage);\r
            }\r
        }\r
    }\r
}"
    }
  }
}}

Tags:
ERC20, Multisig, Swap, Upgradeable, Multi-Signature, Factory|addr:0xad07f58e0cfaf6af19b7ceb86b1ac245cb9db3e1|verified:true|block:23557679|tx:0x438e7d3285edeb71ad9e0bab042a6598253e2a3a7709b790eeae5de824f15f6e|first_check:1760284187

Submitted on: 2025-10-12 17:49:51

Comments

Log in to comment.

No comments yet.