Skip to content

Commit

Permalink
Add deposit and withdraw minimums, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kphed committed Apr 11, 2024
1 parent a8d99e1 commit 12876f1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/MinerETHv2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ contract MinerETHv2 is ERC20, Initializable, ReentrancyGuard {
address private constant _SWAP_REFERRER = address(0);
uint256 private constant _MIN_SHARES_MINTED = 1;
uint256 private constant _MIN_ASSETS_REDEEMED = 1;
uint256 private constant _MIN_DEPOSIT = 1e12;
uint256 private constant _MIN_WITHDRAW = 1e12;
string private constant _TOKEN_NAME_PREFIX = "Brrito Miner-ETH/";
string private constant _TOKEN_SYMBOL_PREFIX = "brrMINER-ETH/";
address private constant _MWETH =
Expand Down Expand Up @@ -151,7 +153,6 @@ contract MinerETHv2 is ERC20, Initializable, ReentrancyGuard {

uint256 sharesBalance = _BRR_ETH_V2.balanceOf(address(this));

// Only convert interest into rewards if it is non-zero.
if (
_totalSupply <
_MOONWELL_HELPER.calculateRedeem(
Expand Down Expand Up @@ -212,7 +213,7 @@ contract MinerETHv2 is ERC20, Initializable, ReentrancyGuard {
* @param memo string Arbitrary data for offchain tracking purposes.
*/
function deposit(string calldata memo) external payable nonReentrant {
if (msg.value == 0) revert InvalidAmount();
if (msg.value < _MIN_DEPOSIT) revert InvalidAmount();

_WETH.deposit{value: msg.value}();
_mine();
Expand All @@ -231,7 +232,7 @@ contract MinerETHv2 is ERC20, Initializable, ReentrancyGuard {
* @param amount uint256 Token amount.
*/
function withdraw(uint256 amount) external nonReentrant {
if (amount == 0) revert InvalidAmount();
if (amount < _MIN_WITHDRAW) revert InvalidAmount();

_mine();
_burn(msg.sender, amount);
Expand Down
50 changes: 45 additions & 5 deletions test/MinerETHv2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ contract MinerETHv2Test is Test {
string public constant TOKEN_SYMBOL = "brrMINER-ETH/ElonRWA";
uint256 public constant TOKEN_DECIMALS = 18;
uint256 public constant DEAD_SHARES_VALUE = 0.01 ether;
uint256 public constant MIN_DEPOSIT = 1e12;
uint256 public constant MIN_WITHDRAW = 1e12;
MinerETHv2Factory public immutable factory = new MinerETHv2Factory();
MinerETHv2 public immutable miner;
IRewardsDistributor public immutable rewardsDistributor;
Expand Down Expand Up @@ -172,6 +174,27 @@ contract MinerETHv2Test is Test {
assertEq(0, rewards);
}

function testMineNoInterest() external {
MinerETHv2 newMiner = MinerETHv2(
payable(factory.deploy(address(WETH)))
);

// Harvest first so that there is no outstanding interest that can be accrued from the deposit.
BRR_ETH_V2.harvest();

newMiner.deposit{value: 1 ether}("");

assertLt(
_calculateAssetsFromRedeem(BRR_ETH_V2.balanceOf(address(newMiner))),
newMiner.totalSupply()
);

(uint256 interest, uint256 rewards) = newMiner.mine();

assertEq(0, interest);
assertEq(0, rewards);
}

function testMineWithMoonwellDeficit() external {
uint256 minDeposit = 2 ether;
uint256 interestAccrualTime = 40;
Expand Down Expand Up @@ -354,6 +377,15 @@ contract MinerETHv2Test is Test {
miner.deposit{value: amount}(memo);
}

function testCannotDepositInvalidAmountFuzz(uint256 amount) external {
amount = bound(amount, 0, MIN_DEPOSIT - 1);
string memory memo = "test";

vm.expectRevert(MinerETHv2.InvalidAmount.selector);

miner.deposit{value: amount}(memo);
}

function testDeposit() external {
BRR_ETH_V2.harvest();

Expand Down Expand Up @@ -420,7 +452,7 @@ contract MinerETHv2Test is Test {
}

function testDepositFuzz(uint256 amount, string calldata memo) external {
amount = bound(amount, 1e9, 1_000 ether);
amount = bound(amount, MIN_DEPOSIT, 1_000 ether);

deal(address(this), amount);

Expand Down Expand Up @@ -478,6 +510,14 @@ contract MinerETHv2Test is Test {
miner.withdraw(amount);
}

function testCannotWithdrawInvalidAmountFuzz(uint256 amount) external {
amount = bound(amount, 0, MIN_WITHDRAW - 1);

vm.expectRevert(MinerETHv2.InvalidAmount.selector);

miner.withdraw(amount);
}

function testWithdraw() external {
uint256 amount = 1 ether;

Expand Down Expand Up @@ -540,7 +580,7 @@ contract MinerETHv2Test is Test {
}

function testWithdrawFuzz(uint256 amount, uint256 skipSeconds) external {
amount = bound(amount, 1e9, 1_000 ether);
amount = bound(amount, MIN_DEPOSIT, 1_000 ether);
skipSeconds = bound(skipSeconds, 60, 365 days);

deal(address(this), amount);
Expand Down Expand Up @@ -608,7 +648,7 @@ contract MinerETHv2Test is Test {
uint256 skipSeconds,
uint256 withdrawalDivisor
) external {
amount = bound(amount, 1e12, 1_000 ether);
amount = bound(amount, MIN_DEPOSIT, 1_000 ether);
skipSeconds = bound(skipSeconds, 60, 365 days);
withdrawalDivisor = bound(withdrawalDivisor, 1, type(uint8).max);

Expand All @@ -621,9 +661,9 @@ contract MinerETHv2Test is Test {
BRR_ETH_V2.harvest();

uint256 _withdrawalAmount = amount / withdrawalDivisor;
uint256 withdrawalAmount = _withdrawalAmount > 1e9
uint256 withdrawalAmount = _withdrawalAmount > MIN_WITHDRAW
? _withdrawalAmount
: 1e9;
: MIN_WITHDRAW;
uint256 tokenBalanceBefore = miner.balanceOf(address(this));
uint256 minerTotalSupply = miner.totalSupply();
(
Expand Down

0 comments on commit 12876f1

Please sign in to comment.