Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/contracts/AbstractARM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ abstract contract AbstractARM is OwnableOperable, ERC20Upgradeable {
function _deposit(uint256 assets, address receiver) internal returns (uint256 shares) {
require(totalAssets() > MIN_TOTAL_SUPPLY || reservedWithdrawLiquidity == 0, "ARM: insolvent");
shares = convertToShares(assets);
require(shares != 0, "ARM: zero shares");

// Transfer liquidity from the depositor before minting LP shares.
IERC20(liquidityAsset).transferFrom(msg.sender, address(this), assets);
Expand Down
8 changes: 6 additions & 2 deletions test/invariants/LidoARM/TargetFunction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ abstract contract TargetFunction is Properties {
// Select a random user
address user = lps[account % lps.length];

amount = uint80(_bound(amount, 0, min(weth.balanceOf(user), type(uint80).max)));
vm.assume(amount > 0);
uint256 totalSupply = lidoARM.totalSupply();
uint256 totalAssets = lidoARM.totalAssets();
uint256 minAmount = totalAssets / totalSupply + 1;
uint256 maxAmount = min(weth.balanceOf(user), type(uint80).max);
vm.assume(minAmount <= maxAmount);
amount = uint80(_bound(amount, minAmount, maxAmount));

// Cache preview deposit
uint256 expectedShares = lidoARM.previewDeposit(amount);
Expand Down
5 changes: 5 additions & 0 deletions test/invariants/OriginARM/TargetFunction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ abstract contract TargetFunction is Properties {
if (CONSOLE_LOG) console.log("deposit() \t\t From: %s | \t Amount: %s", name(user), faa(amount));

// Expected amount of shares
uint256 totalSupply = originARM.totalSupply();
uint256 totalAssets = originARM.totalAssets();
uint256 minAmount = totalAssets / totalSupply + 1;
vm.assume(minAmount <= type(uint88).max);
amount = uint88(_bound(amount, minAmount, type(uint88).max));
uint256 previewDeposit = originARM.previewDeposit(amount);

// Main call
Expand Down
12 changes: 12 additions & 0 deletions test/unit/OriginARM/Deposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ contract Unit_Concrete_OriginARM_Deposit_Test_ is Unit_Shared_Test {
originARM.deposit(DEFAULT_AMOUNT);
}

function test_RevertWhen_Deposit_Because_ZeroShares() public {
// Donating 1 wei increases assets per share enough for a 1 wei deposit to round down to 0 shares.
deal(address(weth), address(originARM), weth.balanceOf(address(originARM)) + 1);
assertEq(originARM.convertToShares(1), 0, "deposit should round to zero shares");

deal(address(weth), alice, 1);

vm.expectRevert("ARM: zero shares");
vm.prank(alice);
originARM.deposit(1);
}

/// @notice Deposits remain priced from gross assets when escrowed redeem shares share a partial loss.
function test_Deposit_When_OutstandingRequestSharesShareSmallLoss()
public
Expand Down
Loading