|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.22; |
| 3 | + |
| 4 | +import {Treasury_Fuzz_Test} from "./_Treasury.fuzz.t.sol"; |
| 5 | + |
| 6 | +import {FixedPointMathLib} from "../../../lib/solmate/src/utils/FixedPointMathLib.sol"; |
| 7 | +import {IERC20} from "../../../lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol"; |
| 8 | +import {ILocker} from "../../../src/lockers/interfaces/ILocker.sol"; |
| 9 | +import {TreasuryV1} from "../../../src/treasury/TreasuryV1.sol"; |
| 10 | + |
| 11 | +/** |
| 12 | + * @notice Fuzz tests for the function "claimYield" of contract "Treasury". |
| 13 | + */ |
| 14 | +contract ClaimYield_Treasury_Fuzz_Test is Treasury_Fuzz_Test { |
| 15 | + using FixedPointMathLib for uint256; |
| 16 | + /* /////////////////////////////////////////////////////////////// |
| 17 | + SETUP |
| 18 | + /////////////////////////////////////////////////////////////// */ |
| 19 | + |
| 20 | + function setUp() public override { |
| 21 | + Treasury_Fuzz_Test.setUp(); |
| 22 | + } |
| 23 | + |
| 24 | + /*////////////////////////////////////////////////////////////// |
| 25 | + TESTS |
| 26 | + //////////////////////////////////////////////////////////////*/ |
| 27 | + function testFuzz_Revert_claimYield_NotOwner(address random, uint256 amount, address receiver) public { |
| 28 | + vm.assume(random != users.dao); |
| 29 | + |
| 30 | + vm.startPrank(random); |
| 31 | + bytes memory expectedError = abi.encodeWithSelector(TreasuryV1.OnlyOwner.selector); |
| 32 | + vm.expectRevert(expectedError); |
| 33 | + treasury.claimYield(amount, receiver); |
| 34 | + vm.stopPrank(); |
| 35 | + } |
| 36 | + |
| 37 | + function testFuzz_Revert_claimYield_YieldTooLow(uint256 totalYield, uint256 amountToClaim, address receiver) |
| 38 | + public |
| 39 | + { |
| 40 | + // Given: availableYield is lower than yield to claim. |
| 41 | + vm.assume(amountToClaim > 1); |
| 42 | + totalYield = bound(totalYield, 0, amountToClaim - 1); |
| 43 | + |
| 44 | + // And: availableYield is set. |
| 45 | + treasury.setAvailableYield(totalYield); |
| 46 | + |
| 47 | + // When: Claiming yield it should revert. |
| 48 | + vm.startPrank(users.dao); |
| 49 | + vm.expectRevert(TreasuryV1.YieldTooLow.selector); |
| 50 | + treasury.claimYield(amountToClaim, receiver); |
| 51 | + vm.stopPrank(); |
| 52 | + } |
| 53 | + |
| 54 | + function testFuzz_Success_claimYield(uint256 totalYield, uint256 amountToClaim, address receiver) public { |
| 55 | + // Given: availableYield is lower than yield to claim. |
| 56 | + // And: Amount to claim should not be equal to max type(uint256).max. |
| 57 | + vm.assume(amountToClaim > 0); |
| 58 | + vm.assume(amountToClaim < type(uint256).max - 2); |
| 59 | + totalYield = bound(totalYield, amountToClaim + 1, type(uint256).max - 1); |
| 60 | + |
| 61 | + // And: availableYield is set. |
| 62 | + treasury.setAvailableYield(totalYield); |
| 63 | + |
| 64 | + // And: Yield is available in the Treasury |
| 65 | + EURE.mint(address(treasury), totalYield); |
| 66 | + |
| 67 | + // When: Claiming yield |
| 68 | + vm.prank(users.dao); |
| 69 | + treasury.claimYield(amountToClaim, receiver); |
| 70 | + |
| 71 | + // Then: Yield should have been sent to receiver |
| 72 | + // And: Available yield should have been lowered. |
| 73 | + assertEq(EURE.balanceOf(receiver), amountToClaim); |
| 74 | + assertEq(EURE.balanceOf(address(treasury)), totalYield - amountToClaim); |
| 75 | + assertEq(treasury.availableYield(), totalYield - amountToClaim); |
| 76 | + assert(treasury.availableYield() > 0); |
| 77 | + } |
| 78 | +} |
0 commit comments