Skip to content

Commit

Permalink
Update Tokemak strat
Browse files Browse the repository at this point in the history
  • Loading branch information
kexleyBeefy committed Nov 20, 2024
1 parent a695c94 commit a156455
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 56 deletions.
4 changes: 3 additions & 1 deletion contracts/BIFI/interfaces/tokemak/ITokemakRewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
77 changes: 22 additions & 55 deletions contracts/BIFI/strategies/Tokemak/StrategyTokemak.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {}
}

0 comments on commit a156455

Please sign in to comment.