Address Details
contract

0x852CD2a8F27928BBaC3f27B91B8d89bBd9eeDcC0

Contract Name
StrategyStakingTripleRewardLP
Creator
0xad3018ā€“0630fc at 0xf7fd4cā€“2013d1
Balance
0 CELO ( )
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
10445080
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
StrategyStakingTripleRewardLP




Optimization enabled
true
Compiler version
v0.8.4+commit.c7e474f2




Optimization runs
200
EVM Version
istanbul




Verified at
2022-08-22T22:24:10.736525Z

contracts/ACFI/strategies/ubeswap/StrategyStakingTripleRewardLP.sol

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "../../interfaces/common/IUniswapRouterETH.sol";
import "../../interfaces/common/IUniswapV2Pair.sol";
import "../../interfaces/synthetix/IStakingRewards.sol";

import "../common/StratManager.sol";
import "../common/FeeManager.sol";
import "../common/BaseStrategyTripleRewardLP.sol";

contract StrategyStakingTripleRewardLP is
  StratManager,
  BaseStrategyTripleRewardLP,
  FeeManager
{
  using SafeERC20 for IERC20;
  using SafeMath for uint256;

  bool public harvestOnDeposit;

  /**
   * @dev Event that is fired each time someone harvests the strat.
   */
  event _SafeSwap(
    uint256 amountOut,
    uint256 amountInMax,
    address[] path,
    address to,
    uint256 deadline
  );

  constructor(
    address _want,
    address _chef,
    StratMgr memory stratMgr,
    address[] memory _outputToNativeRoute,
    address[] memory _outputToLp0Route,
    address[] memory _outputToLp1Route,
    address[] memory _output2ToOutputRoute,
    address[] memory _output3ToOutputRoute
  ) public StratManager(stratMgr) {
    want = _want;
    chef = _chef;
    // console.log("stratMgr %s ", stratMgr.vault);
    require(_outputToNativeRoute.length >= 2);
    output = _outputToNativeRoute[0];
    native = _outputToNativeRoute[_outputToNativeRoute.length - 1];
    outputToNativeRoute = _outputToNativeRoute;
    // setup lp routing
    lpToken0 = IUniswapV2Pair(want).token0();
    require(_outputToLp0Route[0] == output);
    require(_outputToLp0Route[_outputToLp0Route.length - 1] == lpToken0);
    outputToLp0Route = _outputToLp0Route;
    lpToken1 = IUniswapV2Pair(want).token1();
    require(_outputToLp1Route[0] == output);
    require(_outputToLp1Route[_outputToLp1Route.length - 1] == lpToken1);
    outputToLp1Route = _outputToLp1Route;
    // setup 2nd output
    require(_output2ToOutputRoute.length >= 2);
    output2 = _output2ToOutputRoute[0];
    require(_output2ToOutputRoute[_output2ToOutputRoute.length - 1] == output);
    output2ToOutputRoute = _output2ToOutputRoute;
    // setup 3rd output
    require(_output3ToOutputRoute.length >= 2);
    output3 = _output3ToOutputRoute[0];
    require(_output3ToOutputRoute[_output3ToOutputRoute.length - 1] == output);
    output3ToOutputRoute = _output3ToOutputRoute;

    // outputs are not the same
    require(output != output2 && output != output3);
    _giveAllowances();
  }

  // puts the funds to work
  function deposit() public override {
    uint256 wantBal = IERC20(want).balanceOf(address(this));

    if (wantBal > 0) {
      IStakingRewards(chef).stake(wantBal);
    }
  }

  function withdraw(uint256 _amount) external {
    require(msg.sender == vault, "!vault");

    uint256 wantBal = IERC20(want).balanceOf(address(this));

    if (wantBal < _amount) {
      IStakingRewards(chef).withdraw(_amount.sub(wantBal));

      wantBal = IERC20(want).balanceOf(address(this));
    }

    if (wantBal > _amount) {
      wantBal = _amount;
    }

    if (tx.origin == owner() || paused()) {
      IERC20(want).safeTransfer(vault, wantBal);
    } else {
      uint256 withdrawalFeeAmount = wantBal.mul(withdrawalFee).div(
        WITHDRAWAL_MAX
      );
      IERC20(want).safeTransfer(vault, wantBal.sub(withdrawalFeeAmount));
    }
  }

  function beforeDeposit() external override {
    if (harvestOnDeposit) {
      require(msg.sender == vault, "!vault");
      _harvest(nullAddress);
    }
  }

  // performance fees
  function chargeFees(address callFeeRecipient) internal override {
    // take fee from output
    uint256 toNative = IERC20(output).balanceOf(address(this)).mul(45).div(
      1000
    );

    uint256 nativeBal = toNative;
    if (output != native) {
      _safeSwap(toNative, outputToNativeRoute, address(this));
      nativeBal = IERC20(native).balanceOf(address(this));
    } else {
      uint256 balanceLeft = IERC20(native).balanceOf(address(this));
      if (nativeBal > balanceLeft) {
        nativeBal = balanceLeft;
      }
    }

    uint256 callFeeAmount = nativeBal.mul(callFee).div(MAX_FEE);
    if (callFeeRecipient != nullAddress) {
      IERC20(native).safeTransfer(callFeeRecipient, callFeeAmount);
    } else {
      IERC20(native).safeTransfer(tx.origin, callFeeAmount);
    }

    uint256 autocompFeeAmount = nativeBal.mul(autocompFee).div(MAX_FEE);
    IERC20(native).safeTransfer(autocompFeeRecipient, autocompFeeAmount);

    uint256 strategistFee = nativeBal.mul(STRATEGIST_FEE).div(MAX_FEE);
    IERC20(native).safeTransfer(strategist, strategistFee);
  }

  // calculate the total underlaying 'want' held by the strat.
  function balanceOf() public view returns (uint256) {
    return balanceOfWant().add(balanceOfPool());
  }

  // it calculates how much 'want' this contract holds.
  function balanceOfWant() public view returns (uint256) {
    return IERC20(want).balanceOf(address(this));
  }

  // it calculates how much 'want' the strategy has working in the farm.
  function balanceOfPool() public view returns (uint256) {
    uint256 _amount = IStakingRewards(chef).balanceOf(address(this));

    return _amount;
  }

  // called as part of strat migration. Sends all the available funds back to the vault.
  function retireStrat() external {
    require(msg.sender == vault, "!vault");

    IStakingRewards(chef).withdraw(balanceOf());

    uint256 wantBal = IERC20(want).balanceOf(address(this));
    IERC20(want).transfer(vault, wantBal);
  }

  function setHarvestOnDeposit(bool _harvestOnDeposit) external onlyManager {
    harvestOnDeposit = _harvestOnDeposit;

    if (harvestOnDeposit) {
      setWithdrawalFee(0);
    } else {
      setWithdrawalFee(10);
    }
  }

  function _safeSwap(
    uint256 _amountIn,
    address[] memory _path,
    address _to
  ) internal override {
    // swapExactTokensForTokens
    emit _SafeSwap(_amountIn, 0, _path, _to, block.timestamp.add(600));

    if (_amountIn > 0) {
      IUniswapRouterETH(unirouter).swapExactTokensForTokens(
        _amountIn,
        0,
        _path,
        _to,
        block.timestamp.add(600)
      );
    }
  }

  function _addLiquidity(uint256 lp0Bal, uint256 lp1Bal) internal override {
    IUniswapRouterETH(unirouter).addLiquidity(
      lpToken0,
      lpToken1,
      lp0Bal,
      lp1Bal,
      1,
      1,
      address(this),
      block.timestamp
    );
  }

  // pauses deposits and withdraws all funds from third party systems.
  function panic() public onlyManager {
    pause();
    IStakingRewards(chef).withdraw(balanceOf());
  }

  function pause() public onlyManager {
    _pause();

    _removeAllowances();
  }

  function unpause() external onlyManager {
    _unpause();

    _giveAllowances();

    deposit();
  }

  function _giveAllowances() internal {
    IERC20(want).safeApprove(chef, type(uint256).max);
    IERC20(output).safeApprove(unirouter, type(uint256).max);
    IERC20(lpToken0).safeApprove(unirouter, 0);
    IERC20(lpToken0).safeApprove(unirouter, type(uint256).max);
    IERC20(lpToken1).safeApprove(unirouter, 0);
    IERC20(lpToken1).safeApprove(unirouter, type(uint256).max);
    IERC20(output2).safeApprove(unirouter, 0);
    IERC20(output2).safeApprove(unirouter, type(uint256).max);
    IERC20(output3).safeApprove(unirouter, 0);
    IERC20(output3).safeApprove(unirouter, type(uint256).max);
  }

  function _removeAllowances() internal {
    IERC20(want).safeApprove(chef, 0);
    IERC20(output).safeApprove(unirouter, 0);
    IERC20(output2).safeApprove(unirouter, 0);
    IERC20(output3).safeApprove(unirouter, 0);
    IERC20(lpToken0).safeApprove(unirouter, 0);
    IERC20(lpToken1).safeApprove(unirouter, 0);
  }
}
        

/_openzeppelin/contracts/access/Ownable.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _setOwner(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _setOwner(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _setOwner(newOwner);
    }

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
          

/_openzeppelin/contracts/security/Pausable.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
          

/_openzeppelin/contracts/token/ERC20/ERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);

        _afterTokenTransfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}
          

/_openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
          

/_openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
          

/_openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
          

/_openzeppelin/contracts/utils/Address.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
          

/_openzeppelin/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
          

/_openzeppelin/contracts/utils/math/SafeMath.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}
          

/contracts/ACFI/interfaces/common/IUniswapRouterETH.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

interface IUniswapRouterETH {
    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);

    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);

    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);

    function swapExactTokensForTokens(
        uint amountIn, 
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline
    ) external returns (uint[] memory amounts);

    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);

    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
}
          

/contracts/ACFI/interfaces/common/IUniswapV2Pair.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IUniswapV2Pair {
  function factory() external view returns (address);

  function token0() external view returns (address);

  function token1() external view returns (address);

  function burn(address to) external returns (uint256 amount0, uint256 amount1);

  function getReserves()
    external
    view
    returns (
      uint112 reserve0,
      uint112 reserve1,
      uint32 blockTimestampLast
    );
}
          

/contracts/ACFI/interfaces/synthetix/IStakingRewards.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// import "../../../openzeppelin-solidity/contracts/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

// https://docs.synthetix.io/contracts/source/interfaces/istakingrewards
interface IStakingRewards {
  // Views
  function rewardsToken() external view returns (IERC20);

  function stakingToken() external view returns (IERC20);

  function lastTimeRewardApplicable() external view returns (uint256);

  function rewardPerToken() external view returns (uint256);

  function earned(address account) external view returns (uint256);

  function getRewardForDuration() external view returns (uint256);

  function totalSupply() external view returns (uint256);

  function balanceOf(address account) external view returns (uint256);

  // Mutative

  function stake(uint256 amount) external;

  function withdraw(uint256 amount) external;

  function getReward() external;

  function exit() external;
}
          

/contracts/ACFI/strategies/common/BaseStrategyTripleRewardLP.sol

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "../../interfaces/synthetix/IStakingRewards.sol";

import "./StratManager.sol";

abstract contract BaseStrategyTripleRewardLP is StratManager {
  using SafeERC20 for IERC20;
  using SafeMath for uint256;

  // Tokens used
  address public native;
  address public output;
  address public want;
  address public lpToken0;
  address public lpToken1;
  address constant nullAddress = address(0);

  // 2nd reward
  address public output2;

  // 3rd reward
  address public output3;

  // Third party contracts
  address public chef;

  uint256 public lastHarvest;

  // Routes
  address[] public outputToNativeRoute;
  address[] public outputToLp0Route;
  address[] public outputToLp1Route;
  address[] public output2ToOutputRoute;
  address[] public output3ToOutputRoute;

  function chargeFees(address) internal virtual;

  function deposit() public virtual;

  function _safeSwap(
    uint256 _amountIn,
    address[] memory _path,
    address _to
  ) internal virtual;

  function _addLiquidity(uint256 lp0Bal, uint256 lp1Bal) internal virtual;

  //events
  event StratHarvest(address indexed harvester);

  function harvest() external virtual {
    _harvest(nullAddress);
  }

  function harvestWithCallFeeRecipient(address callFeeRecipient)
    external
    virtual
  {
    _harvest(callFeeRecipient);
  }

  function managerHarvest() external onlyManager {
    _harvest(nullAddress);
  }

  // compounds earnings and charges performance fee
  function _harvest(address callFeeRecipient) internal whenNotPaused {
    IStakingRewards(chef).getReward();

    uint256 output2Bal = IERC20(output2).balanceOf(address(this));
    uint256 output3Bal = IERC20(output3).balanceOf(address(this));

    _safeSwap(output2Bal, output2ToOutputRoute, address(this));
    _safeSwap(output3Bal, output3ToOutputRoute, address(this));

    uint256 finalOutputBal = IERC20(output).balanceOf(address(this));

    if (finalOutputBal > 0) {
      chargeFees(callFeeRecipient);
      addLiquidity();
      deposit();
      lastHarvest = block.timestamp;
      emit StratHarvest(msg.sender);
    }
  }

  // Adds liquidity to AMM and gets more LP tokens.
  function addLiquidity() internal {
    uint256 outputHalf = IERC20(output).balanceOf(address(this)).div(2);

    if (lpToken0 != output) {
      _safeSwap(outputHalf, outputToLp0Route, address(this));
    }

    if (lpToken1 != output) {
      _safeSwap(outputHalf, outputToLp1Route, address(this));
    }

    uint256 lp0Bal = IERC20(lpToken0).balanceOf(address(this));
    uint256 lp1Bal = IERC20(lpToken1).balanceOf(address(this));
    if (lp0Bal > 0 && lp1Bal > 0) {
      _addLiquidity(lp0Bal, lp1Bal);
    }
  }
}
          

/contracts/ACFI/strategies/common/FeeManager.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./StratManager.sol";

abstract contract FeeManager is StratManager {
  uint256 public constant STRATEGIST_FEE = 112;
  uint256 public constant MAX_FEE = 1000;
  uint256 public constant MAX_CALL_FEE = 111;

  uint256 public constant WITHDRAWAL_FEE_CAP = 50;
  uint256 public constant WITHDRAWAL_MAX = 10000;

  uint256 public withdrawalFee = 10;

  uint256 public callFee = 111;
  uint256 public autocompFee = MAX_FEE - STRATEGIST_FEE - callFee;

  function setCallFee(uint256 _fee) public onlyManager {
    require(_fee <= MAX_CALL_FEE, "!cap");

    callFee = _fee;
    autocompFee = MAX_FEE - STRATEGIST_FEE - callFee;
  }

  function setWithdrawalFee(uint256 _fee) public onlyManager {
    require(_fee <= WITHDRAWAL_FEE_CAP, "!cap");

    withdrawalFee = _fee;
  }
}
          

/contracts/ACFI/strategies/common/StratManager.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.4.22 <0.9.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

contract StratManager is Ownable, Pausable {
  /**
   * @dev Autocomp Contracts:
   * {keeper} - Address to manage a few lower risk features of the strat
   * {strategist} - Address of the strategy author/deployer where strategist fee will go.
   * {vault} - Address of the vault that controls the strategy's funds.
   * {unirouter} - Address of exchange to execute swaps.
   */
  address public keeper;
  address public strategist;
  address public unirouter;
  address public vault;
  address public harvester;
  address public autocompFeeRecipient;

  struct StratMgr {
    address keeper;
    address strategist;
    address unirouter;
    address vault;
    address harvester;
    address autocompFeeRecipient;
  }

  /**
   * @dev Initializes the base strategy.
   * @param stratMgr.keeper address to use as alternative owner.
   * @param stratMgr.strategist address where strategist fees go.
   * @param stratMgr.unirouter router to use for swaps
   * @param stratMgr.vault address of parent vault.
   * @param stratMgr.autocompFeeRecipient address where to send autocomp's fees.
   */
  constructor(StratMgr memory stratMgr) public {
    keeper = stratMgr.keeper;
    strategist = stratMgr.strategist;
    unirouter = stratMgr.unirouter;
    vault = stratMgr.vault;
    harvester = stratMgr.harvester;
    autocompFeeRecipient = stratMgr.autocompFeeRecipient;
  }

  // checks that caller is either owner or keeper.
  modifier onlyManager() {
    require(msg.sender == owner() || msg.sender == keeper, "!manager");
    _;
  }

  // checks that caller is harvestr.
  modifier onlyHarvester() {
    require(msg.sender == harvester, "!harvester");
    _;
  }

  /**
   * @dev Updates address of the strat keeper.
   * @param _keeper new keeper address.
   */
  function setKeeper(address _keeper) external onlyManager {
    keeper = _keeper;
  }

  /**
   * @dev Updates address of the strat harvester.
   * @param _harvester new harvester address.
   */
  function setHarvester(address _harvester) external onlyManager {
    harvester = _harvester;
  }

  /**
   * @dev Updates address where strategist fee earnings will go.
   * @param _strategist new strategist address.
   */
  function setStrategist(address _strategist) external {
    require(msg.sender == strategist, "!strategist");
    strategist = _strategist;
  }

  /**
   * @dev Updates router that will be used for swaps.
   * @param _unirouter new unirouter address.
   */
  function setUnirouter(address _unirouter) external onlyOwner {
    unirouter = _unirouter;
  }

  /**
   * @dev Updates parent vault.
   * @param _vault new vault address.
   */
  function setVault(address _vault) external onlyOwner {
    vault = _vault;
  }

  /**
   * @dev Updates autocomp fee recipient.
   * @param _autocompFeeRecipient new autocomp fee recipient address.
   */
  function setAutocompFeeRecipient(address _autocompFeeRecipient)
    external
    onlyOwner
  {
    autocompFeeRecipient = _autocompFeeRecipient;
  }

  /**
   * @dev Function to synchronize balances before new user deposit.
   * Can be overridden in the strategy.
   */
  function beforeDeposit() external virtual {}
}
          

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_want","internalType":"address"},{"type":"address","name":"_chef","internalType":"address"},{"type":"tuple","name":"stratMgr","internalType":"struct StratManager.StratMgr","components":[{"type":"address","name":"keeper","internalType":"address"},{"type":"address","name":"strategist","internalType":"address"},{"type":"address","name":"unirouter","internalType":"address"},{"type":"address","name":"vault","internalType":"address"},{"type":"address","name":"harvester","internalType":"address"},{"type":"address","name":"autocompFeeRecipient","internalType":"address"}]},{"type":"address[]","name":"_outputToNativeRoute","internalType":"address[]"},{"type":"address[]","name":"_outputToLp0Route","internalType":"address[]"},{"type":"address[]","name":"_outputToLp1Route","internalType":"address[]"},{"type":"address[]","name":"_output2ToOutputRoute","internalType":"address[]"},{"type":"address[]","name":"_output3ToOutputRoute","internalType":"address[]"}]},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"StratHarvest","inputs":[{"type":"address","name":"harvester","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"_SafeSwap","inputs":[{"type":"uint256","name":"amountOut","internalType":"uint256","indexed":false},{"type":"uint256","name":"amountInMax","internalType":"uint256","indexed":false},{"type":"address[]","name":"path","internalType":"address[]","indexed":false},{"type":"address","name":"to","internalType":"address","indexed":false},{"type":"uint256","name":"deadline","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"MAX_CALL_FEE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"MAX_FEE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"STRATEGIST_FEE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"WITHDRAWAL_FEE_CAP","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"WITHDRAWAL_MAX","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"autocompFee","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"autocompFeeRecipient","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOfPool","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOfWant","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"beforeDeposit","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"callFee","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"chef","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"deposit","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"harvest","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"harvestOnDeposit","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"harvestWithCallFeeRecipient","inputs":[{"type":"address","name":"callFeeRecipient","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"harvester","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"keeper","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastHarvest","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"lpToken0","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"lpToken1","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"managerHarvest","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"native","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"output","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"output2","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"output2ToOutputRoute","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"output3","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"output3ToOutputRoute","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"outputToLp0Route","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"outputToLp1Route","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"outputToNativeRoute","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"panic","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"retireStrat","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setAutocompFeeRecipient","inputs":[{"type":"address","name":"_autocompFeeRecipient","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCallFee","inputs":[{"type":"uint256","name":"_fee","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setHarvestOnDeposit","inputs":[{"type":"bool","name":"_harvestOnDeposit","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setHarvester","inputs":[{"type":"address","name":"_harvester","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setKeeper","inputs":[{"type":"address","name":"_keeper","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setStrategist","inputs":[{"type":"address","name":"_strategist","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setUnirouter","inputs":[{"type":"address","name":"_unirouter","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setVault","inputs":[{"type":"address","name":"_vault","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setWithdrawalFee","inputs":[{"type":"uint256","name":"_fee","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"strategist","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"unirouter","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"vault","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"want","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"withdrawalFee","inputs":[]}]
            

Deployed ByteCode

0x608060405234801561001057600080fd5b506004361061035d5760003560e01c80638456cb59116101d3578063d0e30db011610104578063f20eaeb8116100a2578063fbfa77cf1161007c578063fbfa77cf1461067a578063fcec0dfa1461068d578063fd63a887146106a0578063feaaf04b146106b357600080fd5b8063f20eaeb81461064c578063f2fde38b1461065f578063fb6177871461067257600080fd5b8063dfbdc437116100de578063dfbdc43714610615578063eb0b0fa51461061d578063eedb75aa14610630578063f1a392da1461064357600080fd5b8063d0e30db0146105f2578063d801d946146105fa578063d92f3d731461060257600080fd5b8063a2f8090911610171578063bc063e1a1161014b578063bc063e1a146105bb578063be12a978146105c4578063c1a3d44c146105d7578063c7b9d530146105df57600080fd5b8063a2f8090914610582578063ac1e502514610595578063aced1661146105a857600080fd5b80638bc7e8c4116101ad5780638bc7e8c4146105565780638da5cb5b1461055f57806390321e1a14610570578063a0824cc41461057957600080fd5b80638456cb591461052e578063877562b6146105365780638912cb8b1461054957600080fd5b80634641257d116102ad578063623d8bd21161024b578063722713f711610225578063722713f7146104f8578063748747e6146105005780637d38ca651461051357806380a2e6ac1461051b57600080fd5b8063623d8bd2146104ca5780636817031b146104dd578063715018a6146104f057600080fd5b806354518b1a1161028757806354518b1a14610488578063573fef0a146104915780635c975abb146104995780635ee167c0146104b757600080fd5b80634641257d146104655780634700d3051461046d5780634bdaeac11461047557600080fd5b80631fe4a6861161031a5780632ad5a53f116102f45780632ad5a53f1461042f5780632e1a7d4d1461043757806336c6cf211461044a5780633f4ba83a1461045d57600080fd5b80631fe4a686146103f6578063257ae0de14610409578063264658261461041c57600080fd5b80630e8fbb5a14610362578063115880861461037757806311b0b42d1461039257806315de1daa146103bd5780631f1fcd51146103d05780631fc8bc5d146103e3575b600080fd5b61037561037036600461262d565b6106c6565b005b61037f61073e565b6040519081526020015b60405180910390f35b6007546103a5906001600160a01b031681565b6040516001600160a01b039091168152602001610389565b6103756103cb366004612546565b6107c4565b6009546103a5906001600160a01b031681565b600e546103a5906001600160a01b031681565b6002546103a5906001600160a01b031681565b6003546103a5906001600160a01b031681565b61037561042a366004612665565b610825565b61037f606f81565b610375610445366004612665565b6108c1565b6103a5610458366004612665565b610b05565b610375610b2f565b610375610b88565b610375610b92565b6005546103a5906001600160a01b031681565b61037f61271081565b610375610c44565b600054600160a01b900460ff165b6040519015158152602001610389565b600a546103a5906001600160a01b031681565b6103756104d8366004612546565b610c79565b6103756104eb366004612546565b610c82565b610375610cce565b61037f610d02565b61037561050e366004612546565b610d22565b61037f607081565b6006546103a5906001600160a01b031681565b610375610d83565b600b546103a5906001600160a01b031681565b6018546104a79060ff1681565b61037f60155481565b6000546001600160a01b03166103a5565b61037f60165481565b61037f60175481565b6103a5610590366004612665565b610dd2565b6103756105a3366004612665565b610de2565b6001546103a5906001600160a01b031681565b61037f6103e881565b6103a56105d2366004612665565b610e60565b61037f610e70565b6103756105ed366004612546565b610eec565b610375610f56565b61037561103b565b610375610610366004612546565b61107a565b61037f603281565b6103a561062b366004612665565b6110c6565b600d546103a5906001600160a01b031681565b61037f600f5481565b6008546103a5906001600160a01b031681565b61037561066d366004612546565b6110d6565b61037561116e565b6004546103a5906001600160a01b031681565b600c546103a5906001600160a01b031681565b6103a56106ae366004612665565b61130d565b6103756106c1366004612546565b61131d565b6000546001600160a01b03163314806106e957506001546001600160a01b031633145b61070e5760405162461bcd60e51b815260040161070590612766565b60405180910390fd5b6018805460ff191682151590811790915560ff1615610734576107316000610de2565b50565b610731600a610de2565b600e546040516370a0823160e01b815230600482015260009182916001600160a01b03909116906370a082319060240160206040518083038186803b15801561078657600080fd5b505afa15801561079a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107be919061267d565b92915050565b6000546001600160a01b03163314806107e757506001546001600160a01b031633145b6108035760405162461bcd60e51b815260040161070590612766565b600580546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031633148061084857506001546001600160a01b031633145b6108645760405162461bcd60e51b815260040161070590612766565b606f81111561089e5760405162461bcd60e51b8152600401610705906020808252600490820152630216361760e41b604082015260600190565b6016819055806108b160706103e861284f565b6108bb919061284f565b60175550565b6004546001600160a01b031633146108eb5760405162461bcd60e51b815260040161070590612711565b6009546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b15801561092f57600080fd5b505afa158015610943573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610967919061267d565b905081811015610a5a57600e546001600160a01b0316632e1a7d4d61098c84846114d9565b6040518263ffffffff1660e01b81526004016109aa91815260200190565b600060405180830381600087803b1580156109c457600080fd5b505af11580156109d8573d6000803e3d6000fd5b50506009546040516370a0823160e01b81523060048201526001600160a01b0390911692506370a08231915060240160206040518083038186803b158015610a1f57600080fd5b505afa158015610a33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a57919061267d565b90505b81811115610a655750805b6000546001600160a01b0316321480610a875750600054600160a01b900460ff165b15610aad57600454600954610aa9916001600160a01b039182169116836114e5565b5050565b6000610ad0612710610aca6015548561151590919063ffffffff16565b90611521565b600454909150610b00906001600160a01b0316610aed84846114d9565b6009546001600160a01b031691906114e5565b505050565b60118181548110610b1557600080fd5b6000918252602090912001546001600160a01b0316905081565b6000546001600160a01b0316331480610b5257506001546001600160a01b031633145b610b6e5760405162461bcd60e51b815260040161070590612766565b610b7661152d565b610b7e6115ca565b610b86610f56565b565b610b8660006116fc565b6000546001600160a01b0316331480610bb557506001546001600160a01b031633145b610bd15760405162461bcd60e51b815260040161070590612766565b610bd9610d83565b600e546001600160a01b0316632e1a7d4d610bf2610d02565b6040518263ffffffff1660e01b8152600401610c1091815260200190565b600060405180830381600087803b158015610c2a57600080fd5b505af1158015610c3e573d6000803e3d6000fd5b50505050565b60185460ff1615610b86576004546001600160a01b03163314610b885760405162461bcd60e51b815260040161070590612711565b610731816116fc565b6000546001600160a01b03163314610cac5760405162461bcd60e51b815260040161070590612731565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314610cf85760405162461bcd60e51b815260040161070590612731565b610b866000611a4c565b6000610d1d610d0f61073e565b610d17610e70565b90611a9c565b905090565b6000546001600160a01b0316331480610d4557506001546001600160a01b031633145b610d615760405162461bcd60e51b815260040161070590612766565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b0316331480610da657506001546001600160a01b031633145b610dc25760405162461bcd60e51b815260040161070590612766565b610dca611aa8565b610b86611b30565b60138181548110610b1557600080fd5b6000546001600160a01b0316331480610e0557506001546001600160a01b031633145b610e215760405162461bcd60e51b815260040161070590612766565b6032811115610e5b5760405162461bcd60e51b8152600401610705906020808252600490820152630216361760e41b604082015260600190565b601555565b60108181548110610b1557600080fd5b6009546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b158015610eb457600080fd5b505afa158015610ec8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1d919061267d565b6002546001600160a01b03163314610f345760405162461bcd60e51b815260206004820152600b60248201526a085cdd1c985d1959da5cdd60aa1b6044820152606401610705565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b6009546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b158015610f9a57600080fd5b505afa158015610fae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd2919061267d565b9050801561073157600e5460405163534a7e1d60e11b8152600481018390526001600160a01b039091169063a694fc3a90602401600060405180830381600087803b15801561102057600080fd5b505af1158015611034573d6000803e3d6000fd5b5050505050565b6000546001600160a01b031633148061105e57506001546001600160a01b031633145b610b885760405162461bcd60e51b815260040161070590612766565b6000546001600160a01b031633146110a45760405162461bcd60e51b815260040161070590612731565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b60148181548110610b1557600080fd5b6000546001600160a01b031633146111005760405162461bcd60e51b815260040161070590612731565b6001600160a01b0381166111655760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610705565b61073181611a4c565b6004546001600160a01b031633146111985760405162461bcd60e51b815260040161070590612711565b600e546001600160a01b0316632e1a7d4d6111b1610d02565b6040518263ffffffff1660e01b81526004016111cf91815260200190565b600060405180830381600087803b1580156111e957600080fd5b505af11580156111fd573d6000803e3d6000fd5b50506009546040516370a0823160e01b8152306004820152600093506001600160a01b0390911691506370a082319060240160206040518083038186803b15801561124757600080fd5b505afa15801561125b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061127f919061267d565b6009546004805460405163a9059cbb60e01b81526001600160a01b03918216928101929092526024820184905292935091169063a9059cbb90604401602060405180830381600087803b1580156112d557600080fd5b505af11580156112e9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aa99190612649565b60128181548110610b1557600080fd5b6000546001600160a01b031633146113475760405162461bcd60e51b815260040161070590612731565b600680546001600160a01b0319166001600160a01b0392909216919091179055565b8015806113f25750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b1580156113b857600080fd5b505afa1580156113cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113f0919061267d565b155b61145d5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610705565b6040516001600160a01b038316602482015260448101829052610b0090849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611be4565b60606114cf8484600085611cb6565b90505b9392505050565b60006114d2828461284f565b6040516001600160a01b038316602482015260448101829052610b0090849063a9059cbb60e01b90606401611489565b60006114d28284612830565b60006114d28284612810565b600054600160a01b900460ff1661157d5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610705565b6000805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600e546009546115e9916001600160a01b039182169116600019611369565b600354600854611608916001600160a01b039182169116600019611369565b600354600a54611626916001600160a01b0391821691166000611369565b600354600a54611645916001600160a01b039182169116600019611369565b600354600b54611663916001600160a01b0391821691166000611369565b600354600b54611682916001600160a01b039182169116600019611369565b600354600c546116a0916001600160a01b0391821691166000611369565b600354600c546116bf916001600160a01b039182169116600019611369565b600354600d546116dd916001600160a01b0391821691166000611369565b600354600d54610b86916001600160a01b039182169116600019611369565b600054600160a01b900460ff16156117495760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610705565b600e60009054906101000a90046001600160a01b03166001600160a01b0316633d18b9126040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561179957600080fd5b505af11580156117ad573d6000803e3d6000fd5b5050600c546040516370a0823160e01b8152306004820152600093506001600160a01b0390911691506370a082319060240160206040518083038186803b1580156117f757600080fd5b505afa15801561180b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182f919061267d565b600d546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a082319060240160206040518083038186803b15801561187857600080fd5b505afa15801561188c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118b0919061267d565b905061191782601380548060200260200160405190810160405280929190818152602001828054801561190c57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116118ee575b505050505030611dde565b61197a81601480548060200260200160405190810160405280929190818152602001828054801561190c576020028201919060005260206000209081546001600160a01b031681526001909101906020018083116118ee57505050505030611dde565b6008546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b1580156119be57600080fd5b505afa1580156119d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119f6919061267d565b90508015610c3e57611a0784611ec7565b611a0f6121bf565b611a17610f56565b42600f5560405133907f577a37fdb49a88d66684922c6f913df5239b4f214b2b97c53ef8e3bbb2034cb590600090a250505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006114d282846127f8565b600054600160a01b900460ff1615611af55760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610705565b6000805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586115ad3390565b600e54600954611b4e916001600160a01b0391821691166000611369565b600354600854611b6c916001600160a01b0391821691166000611369565b600354600c54611b8a916001600160a01b0391821691166000611369565b600354600d54611ba8916001600160a01b0391821691166000611369565b600354600a54611bc6916001600160a01b0391821691166000611369565b600354600b54610b86916001600160a01b0391821691166000611369565b6000611c39826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166114c09092919063ffffffff16565b805190915015610b005780806020019051810190611c579190612649565b610b005760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610705565b606082471015611d175760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610705565b843b611d655760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610705565b600080866001600160a01b03168587604051611d8191906126c2565b60006040518083038185875af1925050503d8060008114611dbe576040519150601f19603f3d011682016040523d82523d6000602084013e611dc3565b606091505b5091509150611dd3828286612459565b979650505050505050565b7faa327e5489499adc5f676ea1a378dd62fcf22884ae5855531b1e25c47d956a048360008484611e1042610258611a9c565b604051611e21959493929190612788565b60405180910390a18215610b00576003546001600160a01b03166338ed17398460008585611e5142610258611a9c565b6040518663ffffffff1660e01b8152600401611e71959493929190612788565b600060405180830381600087803b158015611e8b57600080fd5b505af1158015611e9f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c3e919081019061256d565b6008546040516370a0823160e01b8152306004820152600091611f58916103e891610aca91602d916001600160a01b0316906370a082319060240160206040518083038186803b158015611f1a57600080fd5b505afa158015611f2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f52919061267d565b90611515565b60075460085491925082916001600160a01b0390811691161461205a57611fd882601080548060200260200160405190810160405280929190818152602001828054801561190c576020028201919060005260206000209081546001600160a01b031681526001909101906020018083116118ee57505050505030611dde565b6007546040516370a0823160e01b81523060048201526001600160a01b03909116906370a082319060240160206040518083038186803b15801561201b57600080fd5b505afa15801561202f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612053919061267d565b90506120e6565b6007546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b15801561209e57600080fd5b505afa1580156120b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120d6919061267d565b9050808211156120e4578091505b505b60006121036103e8610aca6016548561151590919063ffffffff16565b90506001600160a01b038416156121305760075461212b906001600160a01b031685836114e5565b612147565b600754612147906001600160a01b031632836114e5565b60006121646103e8610aca6017548661151590919063ffffffff16565b600654600754919250612184916001600160a01b039081169116836114e5565b60006121976103e8610aca866070611515565b6002546007549192506121b7916001600160a01b039081169116836114e5565b505050505050565b6008546040516370a0823160e01b8152306004820152600091612242916002916001600160a01b0316906370a082319060240160206040518083038186803b15801561220a57600080fd5b505afa15801561221e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aca919061267d565b600854600a549192506001600160a01b039182169116146122c0576122c081601180548060200260200160405190810160405280929190818152602001828054801561190c576020028201919060005260206000209081546001600160a01b031681526001909101906020018083116118ee57505050505030611dde565b600854600b546001600160a01b0390811691161461233b5761233b81601280548060200260200160405190810160405280929190818152602001828054801561190c576020028201919060005260206000209081546001600160a01b031681526001909101906020018083116118ee57505050505030611dde565b600a546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b15801561237f57600080fd5b505afa158015612393573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123b7919061267d565b600b546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a082319060240160206040518083038186803b15801561240057600080fd5b505afa158015612414573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612438919061267d565b905060008211801561244a5750600081115b15610b0057610b008282612492565b606083156124685750816114d2565b8251156124785782518084602001fd5b8160405162461bcd60e51b815260040161070591906126de565b600354600a54600b5460405162e8e33760e81b81526001600160a01b0392831660048201529082166024820152604481018590526064810184905260016084820181905260a48201523060c48201524260e482015291169063e8e337009061010401606060405180830381600087803b15801561250e57600080fd5b505af1158015612522573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110349190612695565b600060208284031215612557578081fd5b81356001600160a01b03811681146114d2578182fd5b6000602080838503121561257f578182fd5b825167ffffffffffffffff80821115612596578384fd5b818501915085601f8301126125a9578384fd5b8151818111156125bb576125bb6128a8565b8060051b604051601f19603f830116810181811085821117156125e0576125e06128a8565b604052828152858101935084860182860187018a10156125fe578788fd5b8795505b83861015612620578051855260019590950194938601938601612602565b5098975050505050505050565b60006020828403121561263e578081fd5b81356114d2816128be565b60006020828403121561265a578081fd5b81516114d2816128be565b600060208284031215612676578081fd5b5035919050565b60006020828403121561268e578081fd5b5051919050565b6000806000606084860312156126a9578182fd5b8351925060208401519150604084015190509250925092565b600082516126d4818460208701612866565b9190910192915050565b60208152600082518060208401526126fd816040850160208701612866565b601f01601f19169190910160400192915050565b602080825260069082015265085d985d5b1d60d21b604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526008908201526710b6b0b730b3b2b960c11b604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b818110156127d75784516001600160a01b0316835293830193918301916001016127b2565b50506001600160a01b03969096166060850152505050608001529392505050565b6000821982111561280b5761280b612892565b500190565b60008261282b57634e487b7160e01b81526012600452602481fd5b500490565b600081600019048311821515161561284a5761284a612892565b500290565b60008282101561286157612861612892565b500390565b60005b83811015612881578181015183820152602001612869565b83811115610c3e5750506000910152565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b801515811461073157600080fdfea26469706673582212209b43413145a252f986765aa643354554c078b69a69ecec86f57cb2df49ce73be64736f6c63430008040033