Skip to content

Commit

Permalink
feat: revert if zero amount for GenericHarvester
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Oct 25, 2024
1 parent 08d8a28 commit e7fd84f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
25 changes: 11 additions & 14 deletions contracts/helpers/GenericHarvester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,19 @@ contract GenericHarvester is BaseHarvester, IERC3156FlashBorrower, RouterSwapper
YieldBearingParams memory yieldBearingInfo = yieldBearingData[yieldBearingAsset];
(uint8 increase, uint256 amount) = _computeRebalanceAmount(yieldBearingAsset, yieldBearingInfo);
amount = (amount * scale) / 1e9;
if (amount == 0) revert ZeroAmount();

(SwapType swapType, bytes memory data) = abi.decode(extraData, (SwapType, bytes));

if (amount > 0) {
try transmuter.updateOracle(yieldBearingInfo.asset) {} catch {}

adjustYieldExposure(
amount,
increase,
yieldBearingAsset,
yieldBearingInfo.asset,
(amount * (1e9 - maxSlippage)) / 1e9,
swapType,
data
);
}
try transmuter.updateOracle(yieldBearingInfo.asset) {} catch {}
adjustYieldExposure(

Check warning on line 115 in contracts/helpers/GenericHarvester.sol

View check run for this annotation

Codecov / codecov/patch

contracts/helpers/GenericHarvester.sol#L113-L115

Added lines #L113 - L115 were not covered by tests
amount,
increase,
yieldBearingAsset,
yieldBearingInfo.asset,
(amount * (1e9 - maxSlippage)) / 1e9,
swapType,
data
);
}

/// @notice Burns `amountStablecoins` for one yieldBearing asset, swap for asset then mints deposit tokens
Expand Down
9 changes: 7 additions & 2 deletions test/fuzz/GenericHarvester.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,14 @@ contract GenericHarvestertTest is Test, FunctionUtils, CommonUtils {
assertEq(agToken.balanceOf(alice), amount);
}

function test_IncreaseExposure_STEAK_USDC() public {}
function test_Harvest_ZeroAmount() public {
vm.expectRevert(Errors.ZeroAmount.selector);
harvester.harvest(STEAK_USDC, 1e9, abi.encode(uint8(SwapType.VAULT), new bytes(0)));
}

function test_Harvest_IncreaseExposureSTEAK_USDC() public {}

function test_DecreaseExposure_STEAK_USDC() public {}
function test_Harvest_DecreaseExposureSTEAK_USDC() public {}

function _loadReserve(address token, uint256 amount) internal {
if (token == USDM) {
Expand Down

0 comments on commit e7fd84f

Please sign in to comment.