From 632e2a977511b64b010aaf655a6aee9c7efef50c Mon Sep 17 00:00:00 2001 From: midnight-commit <43814957+midnight-commit@users.noreply.github.com> Date: Thu, 23 May 2024 13:18:27 +0200 Subject: [PATCH] add CompoundingJoe (#240) --- .../strategies/mantle/moe/CompoundingJoe.sol | 46 +++++++++++++++++++ .../mantle/moe/interfaces/IJoeStaking.sol | 10 ++++ 2 files changed, 56 insertions(+) create mode 100644 contracts/strategies/mantle/moe/CompoundingJoe.sol create mode 100644 contracts/strategies/mantle/moe/interfaces/IJoeStaking.sol diff --git a/contracts/strategies/mantle/moe/CompoundingJoe.sol b/contracts/strategies/mantle/moe/CompoundingJoe.sol new file mode 100644 index 00000000..bf0a26e9 --- /dev/null +++ b/contracts/strategies/mantle/moe/CompoundingJoe.sol @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.13; + +import "../../BaseStrategy.sol"; + +import "./interfaces/IJoeStaking.sol"; + +contract CompoundingJoe is BaseStrategy { + IJoeStaking public joeStaking; + + constructor(address _joeStaking, BaseStrategySettings memory _settings, StrategySettings memory _strategySettings) + BaseStrategy(_settings, _strategySettings) + { + joeStaking = IJoeStaking(_joeStaking); + } + + function _depositToStakingContract(uint256 _amount, uint256) internal override { + depositToken.approve(address(joeStaking), _amount); + joeStaking.stake(_amount); + } + + function _withdrawFromStakingContract(uint256 _amount) internal override returns (uint256 withdrawAmount) { + joeStaking.unstake(_amount); + return _amount; + } + + function _pendingRewards() internal view override returns (Reward[] memory) { + (address token, uint256 amount) = joeStaking.getPendingReward(address(this)); + Reward[] memory pendingRewards = new Reward[](1); + pendingRewards[0] = Reward({reward: token, amount: amount}); + return pendingRewards; + } + + function _getRewards() internal override { + joeStaking.claim(); + } + + function totalDeposits() public view override returns (uint256) { + return joeStaking.getDeposit(address(this)); + } + + function _emergencyWithdraw() internal override { + joeStaking.unstake(totalDeposits()); + depositToken.approve(address(joeStaking), 0); + } +} diff --git a/contracts/strategies/mantle/moe/interfaces/IJoeStaking.sol b/contracts/strategies/mantle/moe/interfaces/IJoeStaking.sol new file mode 100644 index 00000000..1cf38127 --- /dev/null +++ b/contracts/strategies/mantle/moe/interfaces/IJoeStaking.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.13; + +interface IJoeStaking { + function getDeposit(address account) external view returns (uint256); + function getPendingReward(address account) external view returns (address, uint256); + function stake(uint256 amount) external; + function unstake(uint256 amount) external; + function claim() external; +}