// SPDX-License-Identifier: MIT

pragma solidity ^0.7.6;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";

import { IRebalancePool } from "../interfaces/IRebalancePool.sol";

contract RebalanceWithBonusToken is Ownable {
  using SafeERC20 for IERC20;

  address public immutable stabilityPool;

  address public immutable bonusToken;

  uint256 public bonus;

  constructor(address _stabilityPool, address _bonusToken) {
    stabilityPool = _stabilityPool;
    bonusToken = _bonusToken;
  }

  function liquidate(uint256 _minBaseOut) external {
    IRebalancePool(stabilityPool).liquidate(uint256(-1), _minBaseOut);

    IERC20(bonusToken).safeTransfer(msg.sender, bonus);
  }

  function updateBonus(uint256 _bonus) external onlyOwner {
    bonus = _bonus;
  }
}
[{"inputs":[{"internalType":"address","name":"_stabilityPool","type":"address"},{"internalType":"address","name":"_bonusToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"bonus","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bonusToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minBaseOut","type":"uint256"}],"name":"liquidate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stabilityPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bonus","type":"uint256"}],"name":"updateBonus","outputs":[],"stateMutability":"nonpayable","type":"function"}]