// SPDX-License-Identifier: MIT pragma solidity 0.6.12; import "./libs/Ownable.sol"; import "./libs/SafeMath.sol"; import "./libs/SafeERC20.sol"; import "./libs/ReentrancyGuard.sol"; import "./libs/IAlphaBetaFarm.sol"; import "./libs/Pausable.sol"; contract ABVaultStrategy is Pausable { using SafeERC20 for IERC20; using SafeMath for uint256; address constant nullAddress = address(0); address public want; address public vault; // Third party contracts address public chef; uint256 public poolId; uint256 public lastHarvest; bool public harvestOnDeposit; /** * @dev Event that is fired each time someone harvests the strat. */ event StratHarvest(address indexed harvester); constructor( address _want, uint256 _poolId, address _chef, address _vault ) public { want = _want; chef = _chef; poolId = _poolId; vault = _vault; // _giveAllowances(); } function _giveAllowances() internal { IERC20(want).safeApprove(chef, type(uint256).max); } // puts the funds to work function deposit() public whenNotPaused { uint256 wantBal = IERC20(want).balanceOf(address(this)); if (wantBal > 0) { IAlphaBetaFarm(chef).deposit(poolId, wantBal); } } function withdraw(uint256 _amount) external { require(msg.sender == vault, "!vault"); uint256 wantBal = IERC20(want).balanceOf(address(this)); if (wantBal < _amount) { IAlphaBetaFarm(chef).withdraw(poolId, _amount.sub(wantBal)); wantBal = IERC20(want).balanceOf(address(this)); } } // function beforeDeposit() external override { // if (harvestOnDeposit) { // require(msg.sender == vault, "!vault"); // // _harvest(nullAddress); // } // } function harvest() external virtual { // _harvest(nullAddress); _harvest(); } // compounds earnings and charges performance fee function _harvest() internal whenNotPaused { IAlphaBetaFarm(chef).withdraw(poolId, 0); deposit(); lastHarvest = block.timestamp; emit StratHarvest(msg.sender); } /** * @dev Updates parent vault. * @param _vault new vault address. */ function setVault(address _vault) external { vault = _vault; } // function setHarvestOnDeposit(bool _harvestOnDeposit) external onlyManager { // harvestOnDeposit = _harvestOnDeposit; // if (harvestOnDeposit) { // setWithdrawalFee(0); // } else { // setWithdrawalFee(10); // } // } }