Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ abstract contract BaseAllToNativeFactoryStrat is OwnableUpgradeable, PausableUpg

// compounds earnings and charges performance fee
function _harvest(address callFeeRecipient, bool onDeposit) internal ifNotPaused {
uint beforeBal = balanceOfWant();
_claim();
_swapRewardsToNative();
uint256 nativeBal = IERC20(native).balanceOf(address(this));
if (nativeBal > minAmounts[native]) {
_chargeFees(callFeeRecipient);

_swapNativeToWant();
uint256 wantHarvested = balanceOfWant();
uint256 wantHarvested = balanceOfWant() - beforeBal;
totalLocked = wantHarvested + lockedProfit();
lastHarvest = block.timestamp;

Expand Down
37 changes: 37 additions & 0 deletions forge/test/strategy/BaseAllToNativeFactoryTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@ abstract contract BaseAllToNativeFactoryTest is BaseStrategyTest {
BaseAllToNativeFactoryStrat(payable(vault.strategy())).claim();
}

function test_lockedProfit() external {
BaseAllToNativeFactoryStrat strategy = BaseAllToNativeFactoryStrat(payable(vault.strategy()));
_depositIntoVault(user, wantAmount);
skip(delay);

vm.prank(strategy.keeper());
strategy.setHarvestOnDeposit(false);
uint stratBalBefore = strategy.balanceOf();
beforeHarvest();
strategy.harvest();

uint stratBal = strategy.balanceOf();
uint lockedProfit = strategy.lockedProfit();
assertGt(lockedProfit, 0, "lockedProfit == 0 (Not harvested");
assertEq(stratBal, stratBalBefore, "Only profit should be locked");
assertEq(strategy.lockedProfit(), strategy.totalLocked(), "lockedProfit != totalLocked");
assertEq(stratBal, strategy.balanceOfWant() + strategy.balanceOfPool() - lockedProfit, "Strat.balanceOf != want + pool - lockedProfit");

console.log("User2");
VaultUser user2 = new VaultUser();
deal(vault.want(), address(user2), wantAmount, dealWithAdjust);
_depositIntoVault(user2, wantAmount);
uint stratBalAfterUser2 = strategy.balanceOf();
assertEq(stratBalAfterUser2, wantAmount * 2, "Strat balance should double");

skip(strategy.lockDuration());
assertEq(strategy.lockedProfit(), 0, "lockedProfit != 0 after lockDuration");
assertEq(strategy.balanceOf(), stratBalAfterUser2 + lockedProfit, "Strat balance should grow by lockedProfit");

user.withdrawAll(vault);
user2.withdrawAll(vault);
uint user1Bal = want.balanceOf(address(user));
uint user2Bal = want.balanceOf(address(user2));
assertApproxEqAbs(lockedProfit / 2, user1Bal - wantAmount, 1, "User1 should earn lockedProfit/2");
assertApproxEqAbs(lockedProfit / 2, user2Bal - wantAmount, 1, "User2 should earn lockedProfit/2");
}

function test_rewards() external {
BaseAllToNativeFactoryStrat strategy = BaseAllToNativeFactoryStrat(payable(vault.strategy()));
vm.prank(strategy.keeper());
Expand Down
Loading