Skip to content

Commit

Permalink
Add new factory and update deposit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kphed committed Apr 11, 2024
1 parent bb92cc0 commit 2f758be
Show file tree
Hide file tree
Showing 5 changed files with 796 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/MinerETHv2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract MinerETHv2 is ERC20, Initializable, ReentrancyGuard {
address private constant _SWAP_REFERRER = address(0);
uint256 private constant _DEPOSIT_SLIPPAGE = 1;
uint256 private constant _REDEEM_SLIPPAGE = 1;
string private constant _TOKEN_NAME_PREFIX = "Brrito MinerV2-ETH/";
string private constant _TOKEN_NAME_PREFIX = "Brrito Miner V2-ETH/";
string private constant _TOKEN_SYMBOL_PREFIX = "brrMINERv2-ETH/";
IBrrETHv2 private constant _BRR_ETH_V2 =
IBrrETHv2(0xD729A94d6366a4fEac4A6869C8b3573cEe4701A9);
Expand Down Expand Up @@ -148,8 +148,8 @@ contract MinerETHv2 is ERC20, Initializable, ReentrancyGuard {
_REDEEM_SLIPPAGE
);

// Comet rounding may lead to the redeemed ETH being less than the total supply,
// but the interest accrued per block should more than make up for it.
// Loss from mWETH minting does not scale lineraly with the total deposit amount,
// and the interest and rewards accrued should make a sustained attack infeasible.
if (address(this).balance < _totalSupply) {
_BRR_ETH_V2.deposit{value: address(this).balance}(
address(this),
Expand Down
61 changes: 61 additions & 0 deletions src/MinerETHv2Factory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {FlywheelCore} from "flywheel-v2/FlywheelCore.sol";
import {IFlywheelRewards} from "flywheel-v2/interfaces/IFlywheelRewards.sol";
import {IFlywheelBooster} from "flywheel-v2/interfaces/IFlywheelBooster.sol";
import {LibClone} from "solady/utils/LibClone.sol";
import {Authority} from "solmate/auth/Auth.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {DynamicRewards} from "src/DynamicRewards.sol";
import {MinerETHv2} from "src/MinerETHv2.sol";

contract MinerETHv2Factory {
using LibClone for address;

address private immutable _implementation = address(new MinerETHv2());

/// @notice Deployed minimal proxies for each reward token.
mapping(address rewardToken => address clone) public deployments;

event Deploy(address rewardToken);

error InvalidRewardToken();
error InsufficientMsgValue();

/**
* @notice Deploys a new MinerETHv2 instance for the specified reward token.
* @param rewardToken address Reward token.
* @return clone address MinerETHv2 minimal proxy contract.
*/
function deploy(address rewardToken) external returns (address clone) {
if (rewardToken == address(0)) revert InvalidRewardToken();

// If an ETH mining vault exists for the reward token, return the existing deployment address.
if (deployments[rewardToken] != address(0))
return deployments[rewardToken];

MinerETHv2 miner = MinerETHv2(payable(clone = _implementation.clone()));
FlywheelCore flywheel = new FlywheelCore(
ERC20(rewardToken),
IFlywheelRewards(address(0)),
IFlywheelBooster(address(0)),
address(this),
Authority(address(0))
);
DynamicRewards dynamicRewards = new DynamicRewards(flywheel);
address rewardsStore = address(dynamicRewards.rewardsStore());

// Store the deployment to enable ease of retrieval and prevent redundant deployments.
deployments[rewardToken] = clone;

// Configure flywheel to handle reward accounting and distribution for the mining vault.
// Transfers flywheel ownership to the zero address to prevent further changes.
flywheel.setFlywheelRewards(dynamicRewards);
miner.initialize(rewardToken, address(flywheel), rewardsStore);
flywheel.addStrategyForRewards(ERC20(address(miner)));
flywheel.transferOwnership(address(0));

emit Deploy(rewardToken);
}
}
Loading

0 comments on commit 2f758be

Please sign in to comment.