Skip to content

Conversation

@waelsy123
Copy link
Contributor

this PR is to include tests for core functionalities like deposit, mint, redeem and withdraw

Copy link
Contributor

@godzillaba godzillaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just leave this open for now.

in #141 i've removed the pause thing and we'll handle the 0 assets case + donation attack mitigation separately in a subsequent PR

once we get 141 done let's merge it in here, then merge this one, then do the donation attack mitigation

* wip

* wip: conversion and deposit/withdraw functions look okay

* settargetAllocationWad

* deploy with initial vault

* use factory in core test setup

* slippage tolerance on setTargetAllocationWad

* big simplify

* WIP: mastervault donation attack mitigation (#142)

* wip: dead shares and fix div by zero

* doc

* add one

* initial approval and small refactor

* tests

* fix PerformanceFeesWithdrawn event

* move event

* rebalancing does not count profit

* distribute fees before disabling

* fix maxMint

* fix outdated comment

* remove unused errors

* nonReentrant

* handle max in maxMint

* sanity check we have no sub shares when switching

* init reentrancy guard

* rebalance after setting target

* update docs

* update outdated comment

* fix nonReentrant modifier placement

* remove testFoo

* fix tests
@godzillaba godzillaba merged commit cf71c56 into wa/master-vault-isolated Dec 23, 2025
3 of 9 checks passed
@godzillaba godzillaba deleted the ybb/migrate-tests branch December 23, 2025 17:28
Comment on lines +207 to +228
function _rebalance() internal {
uint256 totalAssetsUp = _totalAssetsLessProfit(MathUpgradeable.Rounding.Up);
uint256 totalAssetsDown = _totalAssetsLessProfit(MathUpgradeable.Rounding.Down);
uint256 idleTargetUp = totalAssetsUp.mulDiv(1e18 - targetAllocationWad, 1e18, MathUpgradeable.Rounding.Up);
uint256 idleTargetDown = totalAssetsDown.mulDiv(1e18 - targetAllocationWad, 1e18, MathUpgradeable.Rounding.Down);
uint256 idleBalance = IERC20(asset()).balanceOf(address(this));

if (idleTargetDown <= idleBalance && idleBalance <= idleTargetUp) {
return;
}
uint256 profitAssets = totalProfit(rounding);
if (profitAssets == 0) {
return 0;

if (idleBalance < idleTargetDown) {
// we need to withdraw from subvault
uint256 assetsToWithdraw = idleTargetDown - idleBalance;
subVault.withdraw(assetsToWithdraw, address(this), address(this));
}
else {
// we need to deposit into subvault
uint256 assetsToDeposit = idleBalance - idleTargetUp;
subVault.deposit(assetsToDeposit, address(this));
}
return _assetsToSubVaultShares(profitAssets, rounding);
}

Check warning

Code scanning / Slither

Unused return Medium

Comment on lines +207 to +228
function _rebalance() internal {
uint256 totalAssetsUp = _totalAssetsLessProfit(MathUpgradeable.Rounding.Up);
uint256 totalAssetsDown = _totalAssetsLessProfit(MathUpgradeable.Rounding.Down);
uint256 idleTargetUp = totalAssetsUp.mulDiv(1e18 - targetAllocationWad, 1e18, MathUpgradeable.Rounding.Up);
uint256 idleTargetDown = totalAssetsDown.mulDiv(1e18 - targetAllocationWad, 1e18, MathUpgradeable.Rounding.Down);
uint256 idleBalance = IERC20(asset()).balanceOf(address(this));

if (idleTargetDown <= idleBalance && idleBalance <= idleTargetUp) {
return;
}
uint256 profitAssets = totalProfit(rounding);
if (profitAssets == 0) {
return 0;

if (idleBalance < idleTargetDown) {
// we need to withdraw from subvault
uint256 assetsToWithdraw = idleTargetDown - idleBalance;
subVault.withdraw(assetsToWithdraw, address(this), address(this));
}
else {
// we need to deposit into subvault
uint256 assetsToDeposit = idleBalance - idleTargetUp;
subVault.deposit(assetsToDeposit, address(this));
}
return _assetsToSubVaultShares(profitAssets, rounding);
}

Check warning

Code scanning / Slither

Unused return Medium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants