diff --git a/contracts/BIFI/interfaces/tokemak/ITokemakRewarder.sol b/contracts/BIFI/interfaces/tokemak/ITokemakRewarder.sol index 885e20c4..071ced07 100644 --- a/contracts/BIFI/interfaces/tokemak/ITokemakRewarder.sol +++ b/contracts/BIFI/interfaces/tokemak/ITokemakRewarder.sol @@ -6,5 +6,7 @@ interface ITokemakRewarder { function stake(address _account, uint256 _amount) external; function withdraw(address account, uint256 amount, bool claim) external; function balanceOf(address _account) external view returns (uint256); - function getReward() external; + function getReward() external; + function stakingToken() external view returns (address); + function rewardToken() external view returns (address); } diff --git a/contracts/BIFI/strategies/Tokemak/StrategyTokemak.sol b/contracts/BIFI/strategies/Tokemak/StrategyTokemak.sol index dd7c675c..b3b32fa5 100644 --- a/contracts/BIFI/strategies/Tokemak/StrategyTokemak.sol +++ b/contracts/BIFI/strategies/Tokemak/StrategyTokemak.sol @@ -10,33 +10,37 @@ import "../../interfaces/common/IERC20Extended.sol"; // Strategy for Tokemak contract StrategyTokemak is BaseAllToNativeFactoryStrat { + using SafeERC20 for IERC20; // Tokens used ITokemakRewarder public rewarder; - address public underlying; function initialize( address _rewarder, - address[] calldata _rewards, - Addresses calldata _commonAddresses - ) public initializer { + Addresses memory _commonAddresses + ) external initializer { rewarder = ITokemakRewarder(_rewarder); - underlying = ITokemakVault(_commonAddresses.want).asset(); + _commonAddresses.want = rewarder.stakingToken(); + _commonAddresses.depositToken = ITokemakVault(_commonAddresses.want).asset(); + address[] memory rewardTokens = new address[](1); + rewardTokens[0] = rewarder.rewardToken(); - __BaseStrategy_init(_commonAddresses, _rewards); - _giveAllowances(); - } - - function balanceOfPool() public view override returns (uint) { - return rewarder.balanceOf(address(this)); + __BaseStrategy_init(_commonAddresses, rewardTokens); } function stratName() public pure override returns (string memory) { return "Tokemak"; } + function balanceOfPool() public view override returns (uint) { + return rewarder.balanceOf(address(this)); + } + function _deposit(uint _amount) internal override { - if (_amount > 0) rewarder.stake(address(this), _amount); + if (_amount > 0) { + IERC20(want).forceApprove(address(rewarder), _amount); + rewarder.stake(address(this), _amount); + } } function _withdraw(uint _amount) internal override { @@ -51,49 +55,12 @@ contract StrategyTokemak is BaseAllToNativeFactoryStrat { rewarder.getReward(); } - function _swapNativeToWant() internal override { - uint256 nativeBal = IERC20(native).balanceOf(address(this)); - if (underlying != native) IBeefySwapper(swapper).swap(native, underlying, nativeBal); - uint256 underlyingBal = IERC20(underlying).balanceOf(address(this)); - ITokemakVault(want).deposit(underlyingBal, address(this)); - } - - function _giveAllowances() internal { - uint max = type(uint).max; - _approve(want, address(rewarder), max); - _approve(native, address(swapper), max); - - _approve(underlying, address(want), 0); - _approve(underlying, address(want), max); - } - - function _removeAllowances() internal { - _approve(want, address(rewarder), 0); - _approve(native, address(swapper), 0); - _approve(underlying, address(want), 0); - } - - function panic() public override onlyManager { - pause(); - _emergencyWithdraw(); - _removeAllowances(); - } - - function pause() public override onlyManager { - _pause(); - _removeAllowances(); - } - - function unpause() external override onlyManager { - _unpause(); - _giveAllowances(); - deposit(); - } - + function _verifyRewardToken(address token) internal view override {} - function _approve(address _token, address _spender, uint amount) internal { - IERC20(_token).approve(_spender, amount); + function _swapNativeToWant() internal override { + _swap(native, depositToken); + uint256 bal = IERC20(depositToken).balanceOf(address(this)); + IERC20(depositToken).forceApprove(want, bal); + ITokemakVault(want).deposit(bal, address(this)); } - - function _verifyRewardToken(address token) internal view override {} }