Skip to content

Commit

Permalink
Convert external error to Staking contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
otsalex committed Nov 25, 2024
1 parent 741c5a2 commit 1e033aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
15 changes: 13 additions & 2 deletions src/modules/adaptors/Staking/MellowStakingAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ERC20, SafeTransferLib, Cellar, PriceRouter, Registry, Math } from "src
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { StakingAdaptor, IWETH9 } from "./StakingAdaptor.sol";
import { IVault } from "src/interfaces/external/IStaking.sol";

/**
* @title Mellow Staking Adaptor
* @notice Allows Cellars to stake with Mellow.
Expand Down Expand Up @@ -57,13 +58,23 @@ import { IVault } from "src/interfaces/external/IStaking.sol";
* @dev Deposit funds into the Mellow staking contract.
* @param _amount The amount of funds to deposit.
*/
function _mintERC20(ERC20, uint256 _amount, uint256, bytes calldata) internal override returns (uint256 shares) {
function _mintERC20(ERC20, uint256 _amount, uint256 _minAmountOut, bytes calldata) internal override returns (uint256 shares) {

baseAsset.safeApprove(address(vaultToken), _amount);

uint256[] memory amounts = new uint256[](1);
amounts[0] = _amount;
(,uint256 shares) = mellowVault.deposit(address(this), amounts, 0, type(uint256).max);

try mellowVault.deposit(address(this), amounts, _minAmountOut, type(uint256).max)
returns (uint256[] memory, uint256 returnedShares) {
return returnedShares;
} catch (bytes memory lowLevelData) {
if (lowLevelData.length >= 4 && bytes4(lowLevelData) == IVault.InsufficientLpAmount.selector) {
return 0;
}
revert(string(lowLevelData));
}

}

/**
Expand Down
34 changes: 17 additions & 17 deletions test/testAdaptors/StakingAdaptors/MellowStakingAdaptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,23 @@ contract MellowStakingAdaptorTest is MainnetStarterTest, AdaptorHelperFunctions
);
}

// function testMintMinAmount() external {
// uint256 mintAmount = 10e18;
// deal(address(primitive), address(this), mintAmount);
// cellar.deposit(mintAmount, address(this));

// // Try minting with an excessive minAmountOut.
// vm.expectRevert(
// bytes(
// abi.encodeWithSelector(
// StakingAdaptor.StakingAdaptor__MinimumAmountNotMet.selector,
// 9974724809485861084,
// type(uint256).max
// )
// )
// );
// _mintDerivative(mintAmount, type(uint256).max);
// }
function testMintMinAmount() external {
uint256 mintAmount = 10e18;
deal(address(primitive), address(this), mintAmount);
cellar.deposit(mintAmount, address(this));

// Try minting with an excessive minAmountOut.
vm.expectRevert(
bytes(
abi.encodeWithSelector(
StakingAdaptor.StakingAdaptor__MinimumAmountNotMet.selector,
0,
type(uint256).max
)
)
);
_mintDerivative(mintAmount, type(uint256).max);
}

function _mintDerivative(uint256 mintAmount, uint256 minAmountOut) internal {
// Rebalance Cellar to mint derivative.
Expand Down

0 comments on commit 1e033aa

Please sign in to comment.