Skip to content

Commit

Permalink
Add Compound strat
Browse files Browse the repository at this point in the history
  • Loading branch information
kexleyBeefy committed Nov 20, 2024
1 parent 0ab378f commit a695c94
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
9 changes: 9 additions & 0 deletions contracts/BIFI/interfaces/compound/IComet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IComet {
function supply(address asset, uint amount) external;
function withdraw(address asset, uint amount) external;
function baseToken() external view returns (address);
}
9 changes: 9 additions & 0 deletions contracts/BIFI/interfaces/compound/ICometRewards.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface ICometRewards {
function claim(address comet, address source, bool shouldAccrue) external;
function rewardConfig(address comet) external view
returns (address token, uint64 rescaleFactor, bool shouldUpscale, uint256 multiplier);
}
63 changes: 63 additions & 0 deletions contracts/BIFI/strategies/Compound/StrategyCompoundV3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../Common/BaseAllToNativeFactoryStrat.sol";

import "../../interfaces/compound/IComet.sol";
import "../../interfaces/compound/ICometRewards.sol";

contract StrategyCompoundV3 is BaseAllToNativeFactoryStrat {
using SafeERC20 for IERC20;

address public cToken;
address public distributor;

function initialize(
address _cToken,
address _distributor,
Addresses memory _addresses
) external initializer {
cToken = _cToken;
distributor = _distributor;

if(_addresses.want == address(0)) _addresses.want = IComet(_cToken).baseToken();
address[] memory rewardTokens = new address[](1);
(address reward,,,) = ICometRewards(distributor).rewardConfig(cToken);
rewardTokens[0] = reward;

__BaseStrategy_init(_addresses, rewardTokens);
}

function stratName() public pure override returns (string memory) {
return "CompoundV3";
}

function balanceOfPool() public view override returns (uint256) {
return IERC20(cToken).balanceOf(address(this));
}

function _deposit(uint amount) internal override {
IERC20(want).forceApprove(cToken, amount);
IComet(cToken).supply(want, amount);
}

function _withdraw(uint amount) internal override {
uint256 cTokenBal = IERC20(want).balanceOf(cToken);
require(cTokenBal >= amount, "Not Enough Underlying");
IComet(cToken).withdraw(want, amount);
}

function _emergencyWithdraw() internal override {
uint256 bal = IERC20(cToken).balanceOf(address(this));
if (bal > 0) IComet(cToken).withdraw(want, bal);
}

function _claim() internal override {
ICometRewards(distributor).claim(cToken, address(this), true);
}

function _verifyRewardToken(address _token) internal view override {
require(_token != cToken, "!cToken");
}
}

0 comments on commit a695c94

Please sign in to comment.